Quantcast
Channel: magick Discussions Rss Feed
Viewing all articles
Browse latest Browse all 3693

New Post: Resizing 5mb gif files throws MemoryAllocationException

$
0
0
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:
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.

Viewing all articles
Browse latest Browse all 3693

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>