how can I resize an animated GIF file using ImageMagick?












43















I want to resize such an animated GIF file do.gif enter image description here



If I do convert do.gif -resize 24x24! do-24.gif I get it resized in do-24.gif but not animated enter image description here



How to resize it right way to get the same animation?










share|improve this question



























    43















    I want to resize such an animated GIF file do.gif enter image description here



    If I do convert do.gif -resize 24x24! do-24.gif I get it resized in do-24.gif but not animated enter image description here



    How to resize it right way to get the same animation?










    share|improve this question

























      43












      43








      43


      18






      I want to resize such an animated GIF file do.gif enter image description here



      If I do convert do.gif -resize 24x24! do-24.gif I get it resized in do-24.gif but not animated enter image description here



      How to resize it right way to get the same animation?










      share|improve this question














      I want to resize such an animated GIF file do.gif enter image description here



      If I do convert do.gif -resize 24x24! do-24.gif I get it resized in do-24.gif but not animated enter image description here



      How to resize it right way to get the same animation?







      imagemagick






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 18 '13 at 17:39









      zubazuba

      1,03822045




      1,03822045






















          3 Answers
          3






          active

          oldest

          votes


















          55














          first run:



          convert do.gif -coalesce temporary.gif


          then



          convert -size <original size> temporary.gif -resize 24x24 smaller.gif





          share|improve this answer



















          • 1





            -coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."

            – sam
            Aug 12 '13 at 19:26






          • 28





            gifsicle --resize 24x24 > do-24.gif can to this too

            – sam
            Aug 14 '13 at 2:20






          • 2





            Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.

            – endolith
            Dec 27 '14 at 21:49








          • 1





            gifsicle produced a much better, optimized output for my use case. Thanks @sam!

            – sj26
            Jul 15 '16 at 8:43






          • 4





            convert temporary.gif -resize 24x24 smaller.gif works for me.,without specifying input size.

            – AMB
            Aug 21 '16 at 17:24



















          2














          I was looking for imagemagick solution as I am familiar with it, but in the end I went with @sam's suggestion of gifsicle (https://www.lcdf.org/gifsicle/). It did just what i wanted, no hassle.



          Can optimise resulting file size in so many different ways, but I went with just reducing the size and reducing number of colors. Worked like a charm:



          gifsicle --resize 48x48 --colors 16 original.gif > smaller.gif






          share|improve this answer































            1














            -coalesce + -deconstruct



            After -coalesce, you likely want to add a -deconstruct:



            convert in.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif


            The root cause of the problem is that your input GIF was properly minimized: GIF allows the next frame to be just the modified rectangle from the previous one at an offset.



            -coalesce then expands all the frames to the original size, which makes the resize work, but it does not re-compress the frames again as your input image: -deconstruct is needed for that!



            Using the test data from this answer: How to create a gif from JPEG images with the command line we can see this clearly with identify:



            $ identify out-convert.gif | head -n 3
            out-convert.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.020u 0:00.019
            out-convert.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019
            out-convert.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019

            $ convert out-convert.gif -resize 256x out.gif
            $ identify out.gif | head -n 3
            out.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
            out.gif[1] GIF 256x256 256x256+125+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
            out.gif[2] GIF 256x258 256x256+123+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009

            $ convert out-convert.gif -coalesce -resize 256x out-coalesce.gif
            $ identify out-coalesce.gif | head -n 3
            out-coalesce.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
            out-coalesce.gif[1] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
            out-coalesce.gif[2] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009

            $ convert out-convert.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif
            $ identify out-deconstruct.gif | head -n 3
            out-deconstruct.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
            out-deconstruct.gif[1] GIF 135x135 256x256+60+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
            out-deconstruct.gif[2] GIF 135x136 256x256+59+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010


            out.gif:



            enter image description here



            out-coalesce.gif:



            enter image description here



            out-deconstruct.gif:



            enter image description here



            First, we see how to input file, out-convert.gif, was in fact compressed, since frame 2 is only 516x516 at offset 252+257, while the full sized frame 1 is 1024x1024.



            Then, if we compare the three conversions:





            • out.gif: All frames are 256x256 or larger, and huge at about 5MiB, TODO why?



              Visually incorrect, since those approximately 256x256 frames have a non-zero offset, e.g. 125+128 for frame 2!




            • out-coalesce.gif: all frames are 256x256 and have the correct offset 0+0.



              Output looks visually correct, but the output file size is 2.0 MiB, which is larger than out-deconstruct.gif




            • out-deconstruct.gif: compressed frames, final output size 1.9 MiB.



              Not considerably smaller than out-coalesce.gif, but I think this is just because the black black ground compresses really well, and it could be very significant in general.




            ffmpeg and gifsicle



            I also tried out the following commands:



            ffmpeg -i out-convert.gif -vf scale=256:-1 out-ffmpeg-small.gif
            gifsicle --resize 256x256 out-convert.gif > out-gifsicle.gif


            and both produced an even smaller correctly looking 1.5 MiB output.



            See also: How to create a gif from JPEG images with the command line



            TODO: why can they make it smaller than convert? Are they just selecting better more minimal diff rectangles, or something else?



            Tested in Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8.






            share|improve this answer

























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "89"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f257831%2fhow-can-i-resize-an-animated-gif-file-using-imagemagick%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              55














              first run:



              convert do.gif -coalesce temporary.gif


              then



              convert -size <original size> temporary.gif -resize 24x24 smaller.gif





              share|improve this answer



















              • 1





                -coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."

                – sam
                Aug 12 '13 at 19:26






              • 28





                gifsicle --resize 24x24 > do-24.gif can to this too

                – sam
                Aug 14 '13 at 2:20






              • 2





                Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.

                – endolith
                Dec 27 '14 at 21:49








              • 1





                gifsicle produced a much better, optimized output for my use case. Thanks @sam!

                – sj26
                Jul 15 '16 at 8:43






              • 4





                convert temporary.gif -resize 24x24 smaller.gif works for me.,without specifying input size.

                – AMB
                Aug 21 '16 at 17:24
















              55














              first run:



              convert do.gif -coalesce temporary.gif


              then



              convert -size <original size> temporary.gif -resize 24x24 smaller.gif





              share|improve this answer



















              • 1





                -coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."

                – sam
                Aug 12 '13 at 19:26






              • 28





                gifsicle --resize 24x24 > do-24.gif can to this too

                – sam
                Aug 14 '13 at 2:20






              • 2





                Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.

                – endolith
                Dec 27 '14 at 21:49








              • 1





                gifsicle produced a much better, optimized output for my use case. Thanks @sam!

                – sj26
                Jul 15 '16 at 8:43






              • 4





                convert temporary.gif -resize 24x24 smaller.gif works for me.,without specifying input size.

                – AMB
                Aug 21 '16 at 17:24














              55












              55








              55







              first run:



              convert do.gif -coalesce temporary.gif


              then



              convert -size <original size> temporary.gif -resize 24x24 smaller.gif





              share|improve this answer













              first run:



              convert do.gif -coalesce temporary.gif


              then



              convert -size <original size> temporary.gif -resize 24x24 smaller.gif






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Feb 18 '13 at 18:12









              phipsalabimphipsalabim

              2,3201112




              2,3201112








              • 1





                -coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."

                – sam
                Aug 12 '13 at 19:26






              • 28





                gifsicle --resize 24x24 > do-24.gif can to this too

                – sam
                Aug 14 '13 at 2:20






              • 2





                Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.

                – endolith
                Dec 27 '14 at 21:49








              • 1





                gifsicle produced a much better, optimized output for my use case. Thanks @sam!

                – sj26
                Jul 15 '16 at 8:43






              • 4





                convert temporary.gif -resize 24x24 smaller.gif works for me.,without specifying input size.

                – AMB
                Aug 21 '16 at 17:24














              • 1





                -coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."

                – sam
                Aug 12 '13 at 19:26






              • 28





                gifsicle --resize 24x24 > do-24.gif can to this too

                – sam
                Aug 14 '13 at 2:20






              • 2





                Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.

                – endolith
                Dec 27 '14 at 21:49








              • 1





                gifsicle produced a much better, optimized output for my use case. Thanks @sam!

                – sj26
                Jul 15 '16 at 8:43






              • 4





                convert temporary.gif -resize 24x24 smaller.gif works for me.,without specifying input size.

                – AMB
                Aug 21 '16 at 17:24








              1




              1





              -coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."

              – sam
              Aug 12 '13 at 19:26





              -coalesce "creates a complete view of the animation at each point, a bit like a true film strip, rather than an animation sequence. Such a sequence, known as a Coalesced Animation is much easier to study, edit, modify and re-optimize."

              – sam
              Aug 12 '13 at 19:26




              28




              28





              gifsicle --resize 24x24 > do-24.gif can to this too

              – sam
              Aug 14 '13 at 2:20





              gifsicle --resize 24x24 > do-24.gif can to this too

              – sam
              Aug 14 '13 at 2:20




              2




              2





              Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.

              – endolith
              Dec 27 '14 at 21:49







              Note that the coalesced view is much larger than the optimized one (3.2 times in my test), and the resizing produces a coalesced image, which can also be larger than the original in file size (2.3 times in my test) even if the resolution is smaller. When I try resizing directly it looks fine and has a small file size, though maybe it just works for this image.

              – endolith
              Dec 27 '14 at 21:49






              1




              1





              gifsicle produced a much better, optimized output for my use case. Thanks @sam!

              – sj26
              Jul 15 '16 at 8:43





              gifsicle produced a much better, optimized output for my use case. Thanks @sam!

              – sj26
              Jul 15 '16 at 8:43




              4




              4





              convert temporary.gif -resize 24x24 smaller.gif works for me.,without specifying input size.

              – AMB
              Aug 21 '16 at 17:24





              convert temporary.gif -resize 24x24 smaller.gif works for me.,without specifying input size.

              – AMB
              Aug 21 '16 at 17:24













              2














              I was looking for imagemagick solution as I am familiar with it, but in the end I went with @sam's suggestion of gifsicle (https://www.lcdf.org/gifsicle/). It did just what i wanted, no hassle.



              Can optimise resulting file size in so many different ways, but I went with just reducing the size and reducing number of colors. Worked like a charm:



              gifsicle --resize 48x48 --colors 16 original.gif > smaller.gif






              share|improve this answer




























                2














                I was looking for imagemagick solution as I am familiar with it, but in the end I went with @sam's suggestion of gifsicle (https://www.lcdf.org/gifsicle/). It did just what i wanted, no hassle.



                Can optimise resulting file size in so many different ways, but I went with just reducing the size and reducing number of colors. Worked like a charm:



                gifsicle --resize 48x48 --colors 16 original.gif > smaller.gif






                share|improve this answer


























                  2












                  2








                  2







                  I was looking for imagemagick solution as I am familiar with it, but in the end I went with @sam's suggestion of gifsicle (https://www.lcdf.org/gifsicle/). It did just what i wanted, no hassle.



                  Can optimise resulting file size in so many different ways, but I went with just reducing the size and reducing number of colors. Worked like a charm:



                  gifsicle --resize 48x48 --colors 16 original.gif > smaller.gif






                  share|improve this answer













                  I was looking for imagemagick solution as I am familiar with it, but in the end I went with @sam's suggestion of gifsicle (https://www.lcdf.org/gifsicle/). It did just what i wanted, no hassle.



                  Can optimise resulting file size in so many different ways, but I went with just reducing the size and reducing number of colors. Worked like a charm:



                  gifsicle --resize 48x48 --colors 16 original.gif > smaller.gif







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 19 '18 at 18:20









                  Peter PerháčPeter Perháč

                  1394




                  1394























                      1














                      -coalesce + -deconstruct



                      After -coalesce, you likely want to add a -deconstruct:



                      convert in.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif


                      The root cause of the problem is that your input GIF was properly minimized: GIF allows the next frame to be just the modified rectangle from the previous one at an offset.



                      -coalesce then expands all the frames to the original size, which makes the resize work, but it does not re-compress the frames again as your input image: -deconstruct is needed for that!



                      Using the test data from this answer: How to create a gif from JPEG images with the command line we can see this clearly with identify:



                      $ identify out-convert.gif | head -n 3
                      out-convert.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.020u 0:00.019
                      out-convert.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019
                      out-convert.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019

                      $ convert out-convert.gif -resize 256x out.gif
                      $ identify out.gif | head -n 3
                      out.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                      out.gif[1] GIF 256x256 256x256+125+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                      out.gif[2] GIF 256x258 256x256+123+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009

                      $ convert out-convert.gif -coalesce -resize 256x out-coalesce.gif
                      $ identify out-coalesce.gif | head -n 3
                      out-coalesce.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                      out-coalesce.gif[1] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                      out-coalesce.gif[2] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009

                      $ convert out-convert.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif
                      $ identify out-deconstruct.gif | head -n 3
                      out-deconstruct.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                      out-deconstruct.gif[1] GIF 135x135 256x256+60+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                      out-deconstruct.gif[2] GIF 135x136 256x256+59+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010


                      out.gif:



                      enter image description here



                      out-coalesce.gif:



                      enter image description here



                      out-deconstruct.gif:



                      enter image description here



                      First, we see how to input file, out-convert.gif, was in fact compressed, since frame 2 is only 516x516 at offset 252+257, while the full sized frame 1 is 1024x1024.



                      Then, if we compare the three conversions:





                      • out.gif: All frames are 256x256 or larger, and huge at about 5MiB, TODO why?



                        Visually incorrect, since those approximately 256x256 frames have a non-zero offset, e.g. 125+128 for frame 2!




                      • out-coalesce.gif: all frames are 256x256 and have the correct offset 0+0.



                        Output looks visually correct, but the output file size is 2.0 MiB, which is larger than out-deconstruct.gif




                      • out-deconstruct.gif: compressed frames, final output size 1.9 MiB.



                        Not considerably smaller than out-coalesce.gif, but I think this is just because the black black ground compresses really well, and it could be very significant in general.




                      ffmpeg and gifsicle



                      I also tried out the following commands:



                      ffmpeg -i out-convert.gif -vf scale=256:-1 out-ffmpeg-small.gif
                      gifsicle --resize 256x256 out-convert.gif > out-gifsicle.gif


                      and both produced an even smaller correctly looking 1.5 MiB output.



                      See also: How to create a gif from JPEG images with the command line



                      TODO: why can they make it smaller than convert? Are they just selecting better more minimal diff rectangles, or something else?



                      Tested in Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8.






                      share|improve this answer






























                        1














                        -coalesce + -deconstruct



                        After -coalesce, you likely want to add a -deconstruct:



                        convert in.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif


                        The root cause of the problem is that your input GIF was properly minimized: GIF allows the next frame to be just the modified rectangle from the previous one at an offset.



                        -coalesce then expands all the frames to the original size, which makes the resize work, but it does not re-compress the frames again as your input image: -deconstruct is needed for that!



                        Using the test data from this answer: How to create a gif from JPEG images with the command line we can see this clearly with identify:



                        $ identify out-convert.gif | head -n 3
                        out-convert.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.020u 0:00.019
                        out-convert.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019
                        out-convert.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019

                        $ convert out-convert.gif -resize 256x out.gif
                        $ identify out.gif | head -n 3
                        out.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                        out.gif[1] GIF 256x256 256x256+125+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                        out.gif[2] GIF 256x258 256x256+123+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009

                        $ convert out-convert.gif -coalesce -resize 256x out-coalesce.gif
                        $ identify out-coalesce.gif | head -n 3
                        out-coalesce.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                        out-coalesce.gif[1] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                        out-coalesce.gif[2] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009

                        $ convert out-convert.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif
                        $ identify out-deconstruct.gif | head -n 3
                        out-deconstruct.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                        out-deconstruct.gif[1] GIF 135x135 256x256+60+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                        out-deconstruct.gif[2] GIF 135x136 256x256+59+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010


                        out.gif:



                        enter image description here



                        out-coalesce.gif:



                        enter image description here



                        out-deconstruct.gif:



                        enter image description here



                        First, we see how to input file, out-convert.gif, was in fact compressed, since frame 2 is only 516x516 at offset 252+257, while the full sized frame 1 is 1024x1024.



                        Then, if we compare the three conversions:





                        • out.gif: All frames are 256x256 or larger, and huge at about 5MiB, TODO why?



                          Visually incorrect, since those approximately 256x256 frames have a non-zero offset, e.g. 125+128 for frame 2!




                        • out-coalesce.gif: all frames are 256x256 and have the correct offset 0+0.



                          Output looks visually correct, but the output file size is 2.0 MiB, which is larger than out-deconstruct.gif




                        • out-deconstruct.gif: compressed frames, final output size 1.9 MiB.



                          Not considerably smaller than out-coalesce.gif, but I think this is just because the black black ground compresses really well, and it could be very significant in general.




                        ffmpeg and gifsicle



                        I also tried out the following commands:



                        ffmpeg -i out-convert.gif -vf scale=256:-1 out-ffmpeg-small.gif
                        gifsicle --resize 256x256 out-convert.gif > out-gifsicle.gif


                        and both produced an even smaller correctly looking 1.5 MiB output.



                        See also: How to create a gif from JPEG images with the command line



                        TODO: why can they make it smaller than convert? Are they just selecting better more minimal diff rectangles, or something else?



                        Tested in Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8.






                        share|improve this answer




























                          1












                          1








                          1







                          -coalesce + -deconstruct



                          After -coalesce, you likely want to add a -deconstruct:



                          convert in.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif


                          The root cause of the problem is that your input GIF was properly minimized: GIF allows the next frame to be just the modified rectangle from the previous one at an offset.



                          -coalesce then expands all the frames to the original size, which makes the resize work, but it does not re-compress the frames again as your input image: -deconstruct is needed for that!



                          Using the test data from this answer: How to create a gif from JPEG images with the command line we can see this clearly with identify:



                          $ identify out-convert.gif | head -n 3
                          out-convert.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.020u 0:00.019
                          out-convert.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019
                          out-convert.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019

                          $ convert out-convert.gif -resize 256x out.gif
                          $ identify out.gif | head -n 3
                          out.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                          out.gif[1] GIF 256x256 256x256+125+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                          out.gif[2] GIF 256x258 256x256+123+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009

                          $ convert out-convert.gif -coalesce -resize 256x out-coalesce.gif
                          $ identify out-coalesce.gif | head -n 3
                          out-coalesce.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                          out-coalesce.gif[1] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                          out-coalesce.gif[2] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009

                          $ convert out-convert.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif
                          $ identify out-deconstruct.gif | head -n 3
                          out-deconstruct.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                          out-deconstruct.gif[1] GIF 135x135 256x256+60+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                          out-deconstruct.gif[2] GIF 135x136 256x256+59+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010


                          out.gif:



                          enter image description here



                          out-coalesce.gif:



                          enter image description here



                          out-deconstruct.gif:



                          enter image description here



                          First, we see how to input file, out-convert.gif, was in fact compressed, since frame 2 is only 516x516 at offset 252+257, while the full sized frame 1 is 1024x1024.



                          Then, if we compare the three conversions:





                          • out.gif: All frames are 256x256 or larger, and huge at about 5MiB, TODO why?



                            Visually incorrect, since those approximately 256x256 frames have a non-zero offset, e.g. 125+128 for frame 2!




                          • out-coalesce.gif: all frames are 256x256 and have the correct offset 0+0.



                            Output looks visually correct, but the output file size is 2.0 MiB, which is larger than out-deconstruct.gif




                          • out-deconstruct.gif: compressed frames, final output size 1.9 MiB.



                            Not considerably smaller than out-coalesce.gif, but I think this is just because the black black ground compresses really well, and it could be very significant in general.




                          ffmpeg and gifsicle



                          I also tried out the following commands:



                          ffmpeg -i out-convert.gif -vf scale=256:-1 out-ffmpeg-small.gif
                          gifsicle --resize 256x256 out-convert.gif > out-gifsicle.gif


                          and both produced an even smaller correctly looking 1.5 MiB output.



                          See also: How to create a gif from JPEG images with the command line



                          TODO: why can they make it smaller than convert? Are they just selecting better more minimal diff rectangles, or something else?



                          Tested in Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8.






                          share|improve this answer















                          -coalesce + -deconstruct



                          After -coalesce, you likely want to add a -deconstruct:



                          convert in.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif


                          The root cause of the problem is that your input GIF was properly minimized: GIF allows the next frame to be just the modified rectangle from the previous one at an offset.



                          -coalesce then expands all the frames to the original size, which makes the resize work, but it does not re-compress the frames again as your input image: -deconstruct is needed for that!



                          Using the test data from this answer: How to create a gif from JPEG images with the command line we can see this clearly with identify:



                          $ identify out-convert.gif | head -n 3
                          out-convert.gif[0] GIF 1024x1024 1024x1024+0+0 8-bit sRGB 256c 16.7865MiB 0.020u 0:00.019
                          out-convert.gif[1] GIF 516x516 1024x1024+252+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019
                          out-convert.gif[2] GIF 515x520 1024x1024+248+257 8-bit sRGB 256c 16.7865MiB 0.030u 0:00.019

                          $ convert out-convert.gif -resize 256x out.gif
                          $ identify out.gif | head -n 3
                          out.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                          out.gif[1] GIF 256x256 256x256+125+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009
                          out.gif[2] GIF 256x258 256x256+123+128 8-bit sRGB 256c 5.0479MiB 0.000u 0:00.009

                          $ convert out-convert.gif -coalesce -resize 256x out-coalesce.gif
                          $ identify out-coalesce.gif | head -n 3
                          out-coalesce.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                          out-coalesce.gif[1] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009
                          out-coalesce.gif[2] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.97683MiB 0.010u 0:00.009

                          $ convert out-convert.gif -coalesce -resize 256x -deconstruct out-deconstruct.gif
                          $ identify out-deconstruct.gif | head -n 3
                          out-deconstruct.gif[0] GIF 256x256 256x256+0+0 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                          out-deconstruct.gif[1] GIF 135x135 256x256+60+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010
                          out-deconstruct.gif[2] GIF 135x136 256x256+59+61 8-bit sRGB 256c 1.87942MiB 0.010u 0:00.010


                          out.gif:



                          enter image description here



                          out-coalesce.gif:



                          enter image description here



                          out-deconstruct.gif:



                          enter image description here



                          First, we see how to input file, out-convert.gif, was in fact compressed, since frame 2 is only 516x516 at offset 252+257, while the full sized frame 1 is 1024x1024.



                          Then, if we compare the three conversions:





                          • out.gif: All frames are 256x256 or larger, and huge at about 5MiB, TODO why?



                            Visually incorrect, since those approximately 256x256 frames have a non-zero offset, e.g. 125+128 for frame 2!




                          • out-coalesce.gif: all frames are 256x256 and have the correct offset 0+0.



                            Output looks visually correct, but the output file size is 2.0 MiB, which is larger than out-deconstruct.gif




                          • out-deconstruct.gif: compressed frames, final output size 1.9 MiB.



                            Not considerably smaller than out-coalesce.gif, but I think this is just because the black black ground compresses really well, and it could be very significant in general.




                          ffmpeg and gifsicle



                          I also tried out the following commands:



                          ffmpeg -i out-convert.gif -vf scale=256:-1 out-ffmpeg-small.gif
                          gifsicle --resize 256x256 out-convert.gif > out-gifsicle.gif


                          and both produced an even smaller correctly looking 1.5 MiB output.



                          See also: How to create a gif from JPEG images with the command line



                          TODO: why can they make it smaller than convert? Are they just selecting better more minimal diff rectangles, or something else?



                          Tested in Ubuntu 18.10, ffpmeg 4.0.2-2, ImageMagick 6.9.10-8.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Jan 25 at 19:11

























                          answered Dec 23 '18 at 18:43









                          Ciro Santilli 新疆改造中心 六四事件 法轮功Ciro Santilli 新疆改造中心 六四事件 法轮功

                          10.1k44750




                          10.1k44750






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Ask Ubuntu!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f257831%2fhow-can-i-resize-an-animated-gif-file-using-imagemagick%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                              ComboBox Display Member on multiple fields

                              Is it possible to collect Nectar points via Trainline?