Skip to content

codejq/ImageProcessor.Core

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

20 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ImageProcessor.Core

 ╔══════════════════════════════════════════════════════════════╗
 β•‘                                                              β•‘
 β•‘   β–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ•—   β–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—                   β•‘
 β•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ•— β–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•—β–ˆβ–ˆβ•”β•β•β•β•β• β–ˆβ–ˆβ•”β•β•β•β•β•                   β•‘
 β•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β–ˆβ–ˆβ–ˆβ–ˆβ•”β–ˆβ–ˆβ•‘β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ–ˆβ•—β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—                     β•‘
 β•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•”β•β•β•                     β•‘
 β•‘   β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘ β•šβ•β• β–ˆβ–ˆβ•‘β–ˆβ–ˆβ•‘  β–ˆβ–ˆβ•‘β•šβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•”β•β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ•—                   β•‘
 β•‘   β•šβ•β•β•šβ•β•     β•šβ•β•β•šβ•β•  β•šβ•β• β•šβ•β•β•β•β•β• β•šβ•β•β•β•β•β•β•                   β•‘
 β•‘                                                              β•‘
 β•‘        P R O C E S S O R  Β·  C O R E                        β•‘
 β•‘                                                              β•‘
 β•‘   Fluent image processing β€” built on .NET, runs anywhere    β•‘
 β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

NuGet Build License: Apache 2.0 .NET Docs


Why do you need this?

  You have an image.                    You want this:
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚  raw photo   β”‚   ─────────────►     β”‚  processed   β”‚
  β”‚  ugly size   β”‚   one fluent chain   β”‚  watermarked β”‚
  β”‚  no watermarkβ”‚                      β”‚  resized     β”‚
  β”‚  wrong formatβ”‚                      β”‚  PNG / WEBP  β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

  Standard .NET gives you this:
    var bmp = new Bitmap(file);
    var g   = Graphics.FromImage(bmp);
    g.DrawImage(...);          // resize β€” 20 lines
    g.DrawString(...);         // watermark β€” 15 lines
    bmp.Save(file, codec);     // format β€” 10 more lines

  ImageProcessor.Core gives you this:
    new ImageFactory()
        .Load(file)
        .Resize(new ResizeLayer(800, 600))
        .Watermark(new TextLayer { Text = "Β© Me" })
        .Format(new PngFormat())
        .Save(output);         // done. 6 lines.

One library. Fluent API. No ceremony. Stop wiring Graphics, ImageCodecInfo, and EncoderParameters by hand. Every operation is a single chained call β€” readable, testable, and composable.


What it can do

  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                   ImageFactory                          β”‚
  β”‚                                                         β”‚
  β”‚  Load ──┬── Resize ──── Crop ──── Rotate ── Save       β”‚
  β”‚         β”‚                                               β”‚
  β”‚         β”œβ”€β”€ Filters ─┬─ GaussianBlur                   β”‚
  β”‚         β”‚            β”œβ”€ GaussianSharpen                 β”‚
  β”‚         β”‚            β”œβ”€ DetectEdges                     β”‚
  β”‚         β”‚            β”œβ”€ Gray / Binary / Halftone        β”‚
  β”‚         β”‚            └─ Tint / Vignette / Hue           β”‚
  β”‚         β”‚                                               β”‚
  β”‚         β”œβ”€β”€ Adjust ──┬─ Brightness / Contrast          β”‚
  β”‚         β”‚            β”œβ”€ Saturation / Gamma              β”‚
  β”‚         β”‚            β”œβ”€ Alpha / ReplaceColor            β”‚
  β”‚         β”‚            └─ Resolution / Quality            β”‚
  β”‚         β”‚                                               β”‚
  β”‚         β”œβ”€β”€ Compose ─┬─ Watermark (text)               β”‚
  β”‚         β”‚            β”œβ”€ Overlay (image on image)        β”‚
  β”‚         β”‚            β”œβ”€ Mask                            β”‚
  β”‚         β”‚            └─ Background / BackgroundColor    β”‚
  β”‚         β”‚                                               β”‚
  β”‚         β”œβ”€β”€ Special ─┬─ Mosaic (pixelated region)      β”‚
  β”‚         β”‚            β”œβ”€ Pixelate                        β”‚
  β”‚         β”‚            β”œβ”€ RoundedCorners                  β”‚
  β”‚         β”‚            β”œβ”€ EntropyCrop (smart crop)        β”‚
  β”‚         β”‚            β”œβ”€ ClearNoise / ClearBackground    β”‚
  β”‚         β”‚            └─ Flip / AutoRotate / Scale       β”‚
  β”‚         β”‚                                               β”‚
  β”‚         └── Format ──┬─ JPEG / PNG / GIF / BMP         β”‚
  β”‚                      └─ (preserves animation in GIF)   β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Install

dotnet add package ImageProcessor.Core.CoreCompat

Or via Package Manager:

Install-Package ImageProcessor.Core.CoreCompat

Quick start

using ImageProcessor;
using ImageProcessor.Imaging;
using ImageProcessor.Imaging.Formats;

// Resize + sharpen + save as PNG
using var factory = new ImageFactory();
factory.Load("input.jpg")
       .Resize(new ResizeLayer(1280, 720))
       .GaussianSharpen(5)
       .Format(new PngFormat())
       .Save("output.png");
// Mosaic (pixelate) a region β€” great for censoring faces / text
factory.Load("screenshot.png")
       .Mosaic(new MosaicLayer(x: 100, y: 50, width: 200, height: 80,
                               size: new Size(10, 10)))
       .Save("censored.png");
// Add a watermark
factory.Load("photo.jpg")
       .Watermark(new TextLayer
       {
           Text     = "Β© My Company",
           FontSize = 24,
           Position = new Point(20, 20),
           Opacity  = 80
       })
       .Save("photo_watermarked.jpg");
// Chain multiple operations
factory.Load("raw.gif")
       .AutoRotate()
       .Resize(new ResizeLayer(800, 600, ResizeMode.Crop))
       .Brightness(10)
       .Contrast(5)
       .Quality(85)
       .Save("final.gif");  // GIF animation preserved

Mosaic / censoring in detail

  Original image           After Mosaic(x:450, y:280, w:140, h:50)
  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
  β”‚                 β”‚      β”‚                 β”‚
  β”‚   [face here]   β”‚      β”‚   [β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ]  β”‚  ← pixelated block
  β”‚                 β”‚      β”‚                 β”‚
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
factory.Load("photo.gif")
       .Mosaic(new MosaicLayer(450, 280, 140, 50, new Size(10, 10)))
       .Save("photo_censored.gif");

Pipeline architecture

              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
   file/streamβ”‚          β”‚
  ──────────► β”‚  .Load() β”‚
              β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
                   β”‚  Image + Format detected
                   β–Ό
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚ Processor chainβ”‚  ◄── each .Method() enqueues a processor
          β”‚  [ P1, P2, P3 ]β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                   β”‚  applied in order
                   β–Ό
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β”‚ .Save()  │──────► file / stream
              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Each processor implements IGraphicsProcessor β€” you can also add your own:

public class MyProcessor : IGraphicsProcessor
{
    public Image ProcessImage(ImageFactory factory)
    {
        // manipulate factory.Image
        return factory.Image;
    }
}

factory.Load("img.png")
       .ApplyProcessor(new MyProcessor())
       .Save("out.png");

Target frameworks

Framework Support Notes
.NET Standard 2.0 βœ… .NET Framework 4.6.1+, .NET Core 2.0+
.NET 8 (Windows) βœ… Uses native GDI+ via System.Drawing.Common
.NET 9 (Windows) βœ… Uses native GDI+ via System.Drawing.Common

System.Drawing.Common is Windows-only on .NET 6+. This library targets net8.0-windows and net9.0-windows for modern .NET to make that constraint explicit and safe.


Contributing

PRs and issues welcome. Please open an issue before submitting large changes.


License

Apache License 2.0 β€” originally by James Jackson-South, extended here with additional processors (Mosaic, ClearNoise, Binary, etc.).

About

πŸ“· A fluent wrapper around System.Drawing.Common for the processing of image files. http://imageprocessor.org

Resources

Stars

0 stars

Watchers

1 watching

Forks

Packages

 
 
 

Contributors

Languages