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 and 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#.

Click Here to learn more smart tricks and tips related to ASP.NET MVC C# programming.

Article by

Chintan Prajapati

Chintan Prajapati, a seasoned computer engineer with over 20 years in the software industry, is the Founder and CEO of Satva Solutions. His expertise lies in Accounting & ERP Integrations, RPA, and developing technology solutions around leading ERP and accounting software, focusing on using Responsible AI and ML in fintech solutions. Chintan holds a BE in Computer Engineering and is a Microsoft Certified Professional, Microsoft Certified Technology Specialist, Certified Azure Solution Developer, Certified Intuit Developer, and Xero Developer.Throughout his career, Chintan has significantly impacted the accounting industry by consulting and delivering integrations and automation solutions that have saved thousands of man-hours. He aims to provide readers with insightful, practical advice on leveraging technology for business efficiency.Outside of his professional work, Chintan enjoys trekking and bird-watching. Guided by the philosophy, "Deliver the highest value to clients". Chintan continues to drive innovation and excellence in digital transformation strategies from his base in Ahmedabad, India.