Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest Image Resizing in .NET [closed]

I need the fastest library to resize full size images (some up to 9MB in size) to multiple sizes.

Here's the scenerio:

  • User uploads a photo
  • a FileSystemWatcher is running in a service watching the drop location (on a SAN)
  • When a new photo appears, the service will create 4 versions of the image at full JPEG quality:
    • 100px wide
    • 320px wide
    • 640px wide
    • 1280 wide

I'm not fussed if the library is C/C++ or anything else for that matter, as long as I can tap into it via .NET it's cool.

Also this will need to scale to possibly 1,000 active users.

Let me know your thoughts :)

like image 433
Ash Avatar asked Jul 28 '09 15:07

Ash


4 Answers

Here is winforms way

public Image ResizeImage( Image img, int width, int height )
{
    Bitmap b = new Bitmap( width, height ) ;
    using(Graphics g = Graphics.FromImage( (Image ) b ))
    {       
         g.DrawImage( img, 0, 0, width, height ) ;
    }

    return (Image ) b ;
}

and here is WPF way TransformedBitmap Class

like image 99
Arsen Mkrtchyan Avatar answered Nov 04 '22 03:11

Arsen Mkrtchyan


I recommend ImageResizer:

Key features are:

  • RESTful url-based image API (example: src="img.jpg?w=170")
  • Intuitively crop, resize, rotate, flip, constrain, and encode
  • Render PDFs into images
  • 19 free plugins cover most common tasks
  • Disk + Memory input/output caching
  • 8-bit PNG/GIF & animated GIF processing
  • Flexible text & image overlay support
  • Image filtering suite (needs licence)
  • High performance
  • and more ....

For installing with Nuget:

PM> Install-Package ImageResizer.MvcWebConfig
PM> Install-Package ImageResizer.Plugins.DiskCache
PM> Install-Package ImageResizer.Plugins.PrettyGifs

For more information please check: http://imageresizing.net/docs/install/nuget

like image 22
pixparker Avatar answered Nov 04 '22 01:11

pixparker


There are a lot of articles out there showing the basics of this. I've used the components from Atalasoft and found them to be of pretty good quality. There are nuances to resizing and working with JPEG images.

You seem to be really concerned with performance but you don't really give enough information to help us suggest good optimizations for you. Whatever you are doing, you need to do a full performance analysis and understand what is running slow. In some cases slowish, but maintainable image processing code may be OK if other things are optimized.

One solution for good performance is to queue incoming files that need to be converted. Add more machines to handle more messages in the queue, or optimize the service code to get better throughput. It's really not that difficult to handle a large number of users if you get the design right.

like image 6
Brian Lyttle Avatar answered Nov 04 '22 03:11

Brian Lyttle


If money is no object, LeadTools is the traditional "go to" library for image processing. That being said, my first inclination would be to code it up using stock .NET GDI+ calls and then do some testing. It is likely this solution would be performant enough, but if not, you'll have a baseline from which you can compare other libraries and solutions. Anything involving spawning a command line tool will entail creating a separate process for each image, which could negate the benefit of going to unmanaged code.

like image 2
Michael A. McCloskey Avatar answered Nov 04 '22 02:11

Michael A. McCloskey