Hi,
I've used Magick.NET to create Micro-service which makes resizing of different types of images.
It works like a charms, except one case - resizing of big .gif files.
When I'm trying to resize about 4-5 gif animations concurrently I'm usually get MemoryAllocationException somewhere inside collection.ToByteArray(). Even when I'm trying to avoid duplicating of collection as byte array, and trying to write resized image directly to filesystem I'm getting same exception in collection.Write() method.
Here is my code:
Simplest implementation:
Dmitry Zaets.
I've used Magick.NET to create Micro-service which makes resizing of different types of images.
It works like a charms, except one case - resizing of big .gif files.
When I'm trying to resize about 4-5 gif animations concurrently I'm usually get MemoryAllocationException somewhere inside collection.ToByteArray(). Even when I'm trying to avoid duplicating of collection as byte array, and trying to write resized image directly to filesystem I'm getting same exception in collection.Write() method.
Here is my code:
Simplest implementation:
using (var collection = new MagickImageCollection(path))
{
collection.Coalesce();
foreach (MagickImage image in collection)
{
image.Resize(width, height);
}
return collection.ToByteArray();
}
Optimized version:using (var collection = new MagickImageCollection(path))
{
collection.Coalesce();
foreach (MagickImage image in collection)
{
image.Resize(width, height);
}
collection.Optimize();
collection.OptimizeTransparency();
collection.Write(path);
}
Regards,Dmitry Zaets.