Handle Image with ImageProcessor in C#

ImageProcessor is a collection of lightweight libraries written in C# that allows you to manipulate images on-the-fly using .NET 4.5+

It’s lighting fast, extensible, easy to use, comes bundled with some great features and is fully open source.

What Is ImageProcessor?

ImageProcessor is a collection of lightweight libraries written in C# that allows you to manipulate images on-the-fly using .NET 4.5+

It consists of two main libraries ImageProcessor - For desktop and application use and ImageProcessor.Web - a dynamic image processing extension built for ASP.NET.

How To Use

public static void ImageProcessing(string imagePath, string outputPath)
{
    byte[] photoBytes = File.ReadAllBytes(imagePath); // change imagePath with a valid image path
    int quality = 100;
    var format = new PngFormat(); // we gonna convert a image to a png one
    var size = new Size(600, 600);

    using (var inStream = new MemoryStream(photoBytes))
    {
            // Initialize the ImageFactory using the overload to preserve EXIF metadata.
            using (var imageFactory = new ImageFactory(preserveExifData: true))
            {
                // Do your magic here
                imageFactory.Load(inStream)
                    .Rotate(90)
                    .RoundedCorners(new RoundedCornerLayer(190, true, true, true, true))
                    .Watermark(new TextLayer()
                    {
                        DropShadow = true,
                        FontFamily = FontFamily.GenericSerif,
                        Text = "Top Nguyen, ahihi",
                        FontSize = 400,
                        Style = FontStyle.Bold,
                        FontColor = Color.BlueViolet
                    })
                    .Resize(size)
                    .Format(format)
                    .Quality(quality)
                    .Save(outputPath);
        }
    }
}

I'm going to test this code snippet on this image.

And the result is this below.

Very easy and "beautiful", it help me save much time for image processing.

You can download full my demo code by this link.

An Important NuGet Note

ImageProcessor

PM> Install-Package ImageProcessor

ImageProcessor.Web

PM> Install-Package ImageProcessor.Web

ImageProcessor.Web.Config

PM> Install-Package ImageProcessor.Web.Config

Github link

Wiki link

Website link

Summary

Have you ever wanted to manipulate images from your C# program but don't know how or maybe you started writing your custom code from scratch and you found that it's a lot harder and painful than it looks. From now on don't push yourself too hard most of the work is done for you in ImageProcessor.

Happy Coding!