I'm using ImageSharp to convert some JPEG files from 4000x4000 (or so) images down to a set of different sized thumbnails (100x100, 250x250, 500x500 etc). The code below works pretty well, but wondering about any performance improvements - resizing and saving 3 thumbnails takes around a second per image, which isn't bad, but I'm wondering if there are any optimisations I can do to make it faster?
var sizes = new[] { new Size (100), new Size (250), new Size (500) };
using (var image = Image.Load<Rgb24>(sourceFileName))
{
foreach (var size in sizes)
{
image.Mutate(x => x.Resize(size.Width, size.Height));
image.Save(dest);
}
}
I know this lib will probably never get to the performance of GraphicsMagick (which is native C++ and highly optimised, and can do the same load + thumbnail transform in about 200ms) but I like the fact that it's cross-platform.
The lion's share of the time to do the work in ImageSharp is taken loading the image - is there a way to give it hints to load the JPEG in a faster way given that a lot of the resolution is going to be discarded with the thumbnail reduction anyway? Once it's loaded, the actual Resize and save-to-disk seems pretty quick.
I've also tried using a threadpool to transform (say) 6 images in parallel, which does give some improvement, but I just want to check if there's options or usage changes in ImageSharp itself that will make this significantly faster - checked the docs, but nothing obvious I can see so far.