Resize images using Image Processor in asp.net c#

What is it Image Processor?

Image Processor contains many libraries that are written in Asp.Net C#.

it is also known as a media processor.

in which you can easily manipulate images using Asp.Net 4.5+ in C#. It has multiple methods to manipulate images, it uses the Image Factory class.

Problems with Resigning Images

I have developed a project in Umbraco cms.

I want to display only one image on multiple pages with various sizes.

In the image folder, I saved an image with a different size.

For example:

  • TestImage_200x200.jpg
  • TestImage_400x400.jpg

but this is not a proper way.

The solution with Image Processor Library:

I have found a solution to resize only a single image in different sizes.

I have installed ImageProcessor in my application.

You can download ImageProcessor libraries via Nuget because its simplest and fastest way to install it.

Image Processor ( https://www.nuget.org/packages/ImageProcessor/)

ImageProcessor generally uses an extension called ImageProcessor.web that allows you to manipulate images via Url API of query string parameters.

And ImageProcessor.The Web uses an ImageProcessingModule class that provides various methods to perform some functions using a query string.

Resize image:

You can resize images in a different dimension with excellent quality to size ratio there are six different types of methods available as follows.

  • Pad (default)
  • BoxPad
  • Crop
  • Min
  • Max
  • Stretch

You have to pass the following parameters to resize the image as follows:-


<img src="~/Images/banner.jpg?width=300&height=300" alt="Banner Image" />
<img src="~/Images/banner.jpg?width=300&height=300&mode=crop" alt="Banner Image" />

Provided Methods:

  • Resize, Rotate, Rounded Corners, Flip
  • Crop, Watermark, Filter, Saturation,
  • Brightness, Contrast, Quality, Format,
  • Vignette, Gaussian Blur, Gaussian Sharpen, and Transparency.

Example:

Original Image:

resize image by image processor in asp net 1

Resize Crop:

resize image by image processor in asp net 2

Conclusion:

Using Parameters like width, height, mode, and anchor we can resize images easily using ImageProcessor in Asp.Net C#.

Article by

Chintan Prajapati

Chintan Prajapati is the Founder and CEO of Satva Solutions and a seasoned computer engineer with over two decades of experience in the software industry. His expertise spans Accounting & ERP Integrations, Robotic Process Automation, and the development of technology solutions built around leading ERP and accounting platforms with a particular focus on responsible AI and machine learning in fintech.Chintan holds a BE in Computer Engineering and carries an impressive roster of certifications, including Microsoft Certified Professional, Microsoft Certified Technology Specialist, Certified Azure Solution Developer, Certified Intuit Developer, Certified QuickBooks ProAdvisor, and Xero Developer.Over the course of his career, he has made a measurable impact on the accounting industry consulting on and delivering integration and automation solutions that have collectively saved thousands of man-hours. His writing aims to offer readers practical, insight-driven advice on harnessing technology to unlock greater business efficiency.When he steps away from the desk, Chintan can be found trekking through mountain trails or watching birds in the wild. Grounded in the philosophy of delivering the highest value to clients, he continues to champion innovation and excellence in digital transformation from his home base in Ahmedabad, India.