Example #1
0
        public static void CreateCollection(GifData gifData)
        {
            using var imgCollection = new MagickImageCollection();

            foreach (var frameLocation in gifData.FrameFileLocations)
            {
                var frame = new MagickImage(frameLocation);
                frame.ApplyGifSettings(gifData);
                imgCollection.Add(frame);
            }

            if (!imgCollection.All(img => img.IsSameBaseSize(imgCollection[0])))
            {
                Console.WriteLine("Please ensure all image frames have the same size dimensions");
                return;
            }

            var settings = new QuantizeSettings
            {
                Colors       = 256,
                DitherMethod = DitherMethod.No
            };

            imgCollection.Quantize(settings);

            Console.WriteLine("Rendering gif...");

            var path = Path.Combine(gifData.OutputLocation, gifData.FileName);

            if (!path.EndsWith(".gif", StringComparison.InvariantCultureIgnoreCase))
            {
                path += ".gif";
            }

            imgCollection.Write(path, MagickFormat.Gif);
        }