예제 #1
0
        public override int Run(string[] remainingArguments)
        {
            var backgroundImage = new Bitmap(ImageDimensions.X, ImageDimensions.Y);

            using (var gfx = Graphics.FromImage(backgroundImage))
                foreach (var widget in Steps)
                {
                    widget.DrawBackground(gfx);
                }

            backgroundImage.Save(Output);

            List <ConcurrentGifsCommand.Frame> animationFrames = new List <ConcurrentGifsCommand.Frame>();

            foreach (var widget in Steps)
            {
                var lastPosition = 0;
                if (animationFrames.Any())
                {
                    lastPosition = animationFrames.Last().End;
                }

                animationFrames.AddRange(widget.GetFrames(lastPosition));
            }

            if (RemoveEveryNFrames.HasValue)
            {
                animationFrames = animationFrames.Where((f, i) => (i + 1) % RemoveEveryNFrames.Value != 0).ToList();
            }

            ConcurrentGifsCommand.WriteBackgroundForFrames(backgroundImage, animationFrames, Output);

            var currentFrame = 0;

            ImageResizerUtil.ProcessImage(
                new PluginList().WithAnimatedGifExtensions()
                .WithPlugin(new AnimationVisitorExtension((bitmap, graphics, delay) =>
            {
                var animationFrame = animationFrames[currentFrame];
                foreach (var widget in Steps)
                {
                    widget.DrawFrame(animationFrame, graphics);
                }

                currentFrame++;
            })).Plugins,
                source: Output, target: Output);

            ImageResizerUtil.ProcessImage(
                new PluginList().WithAnimatedGifExtensions().Plugins,
                source: Output, target: Output,
                resizeSettings: new ResizeSettings(MaximumWidth, int.MaxValue, FitMode.Max, null));

            Console.WriteLine("Created filesize of {0} was {1}k.", Path.GetFullPath(Output), new FileInfo(Output).Length / 1000.0);

            return(0);
        }
예제 #2
0
        public override int Run(string[] remainingArguments)
        {
            var extensions = new IPlugin[] { new PrettyGifs(), new AnimatedGifs(), new NoopExtension() };
            var source     = remainingArguments[0];
            var target     = remainingArguments[1];

            ImageResizerUtil.ProcessImage(extensions, source, target);

            return(0);
        }
예제 #3
0
        public override int Run(string[] remainingArguments)
        {
            using (var output = File.OpenWrite(Output))
                using (var outputWriter = new GifEncoder(output))
                {
                    foreach (var inputFile in Inputs)
                    {
                        ImageResizerUtil.ProcessImage(
                            new PluginList().WithAnimatedGifExtensions().WithPlugin(new AnimationVisitorExtension((bitmap, graphic, delay) =>
                        {
                            outputWriter.FrameDelay = TimeSpan.FromMilliseconds(delay);
                            outputWriter.AddFrame(bitmap);
                        })).Plugins,
                            inputFile);
                    }
                }

            return(0);
        }
예제 #4
0
        public override int Run(string[] remainingArguments)
        {
            var frames = GetFramesForSequentialAnimations(this.Inputs);

            var background = Image.FromFile(BackgroundImage);

            WriteBackgroundForFrames(background, frames, Output);

            int position = 0;

            ImageResizerUtil.ProcessImage(
                new PluginList().WithAnimatedGifExtensions().WithPlugin(new AnimationVisitorExtension((bitmap, graphics, delay) =>
            {
                graphics.DrawImageUnscaled(frames[position].Image, 0, 0);
                position++;
            })).Plugins,
                source: Output, target: Output);

            return(0);
        }
예제 #5
0
        public static Frame[] GetFramesForSequentialAnimations(IEnumerable <string> inputs, int startTime = 0)
        {
            List <Frame> frames = new List <Frame>();

            int currentTime = startTime;

            foreach (var input in inputs)
            {
                ImageResizerUtil.ProcessImage(
                    new PluginList().WithAnimatedGifExtensions().WithPlugin(new AnimationVisitorExtension((bitmap, graphic, duration) =>
                {
                    frames.Add(new Frame()
                    {
                        Start    = currentTime,
                        Duration = duration,
                        Image    = bitmap
                    });

                    currentTime += duration;
                })).Plugins,
                    input);
            }
            return(frames.ToArray());
        }