ImageMagick Animated GIF not working correctly - imagemagick

I am trying to upload some animated GIFs. Some work great, others get messed up as seen in the attached example. Here is my basic ImageMagick command:
exec(" convert elephant_upload.gif -strip -resize 600x600 elephant_output.gif ");
Anyone know what im doing wrong here?
Original Gif:
Processed Gif:

You need to coalesce your frames in Imagemagick before resizing in your command. So try
convert elephant.gif -strip -coalesce -resize 600x600 -layers optimize x.gif

Related

PNG-Preview of animated GIF with ImageMagick is distorted

I am creating preview images of all JPG/PNG/GIF that are uploaded to our server.
For this I use ImageMagick with:
convert -format jpg -quality 90 -strip -background white -flatten -alpha off +repage -resize '255x255>' ".$locationtmp." -write '".$preview."'");
The parameters added are to flatten the background (make it white instead of black).
However, when using the code to create a preview of an animated GIF, the result is distorted.
Example of a distorted result:
I tried to add the +repage parameter but it did not help.
How to get a nice preview of the GIF as PNG? It could also be just the first frame.
In Imagemagick, if you want a preview image for all formats including gif and want just the first frame of the animation for the preview, then just add [0] to the filename, such as animation.gif[0]. This will take the first frame of the animation and the only frames of the other formats such as JPG and PNG that only allow one frame. The appended [0] does not hurt the other formats.
So use
image.suffix[0] in place of just image.suffix
for generating a single image preview

ImageMagick rotate animated gif glitches

I'm using ImageMagick to rotate animated gifs. Simply:
convert image.gif -rotate 32 -alpha set -background none output.gif
Output:
https://s3-eu-west-1.amazonaws.com/uploads-eu.hipchat.com/108112/892631/ATp8mXXrDdSkCNu/sowa-test2.gif
Does anyone have a clue why output image is distorted this way and how to avoid this?
Without seeing the original image, I would suggest extracting each image, apply rotation, and then re-build the animated gif.
Example using the following gif:
convert anim_none.gif -scene 1 +adjoin tmp_%02d.gif
mogrify -rotate 32 -alpha set -background none tmp_*.gif
convert tmp_*.gif -loop 0 final.gif
And note: quality is expected to degrade with rotation operations.
The solution from emcconville didn't quite work for me. Part of the issue may have been that my layers were transparent and so not all the same dimensions. However, using his solution as a base and then modifying it based on things I saw elsewhere, I was able to get my gif rotated:
convert my_gif.gif -background transparent \
-virtual-pixel background -coalesce tmp_%02d.gif
mogrify -rotate -45 -background transparent -virtual-pixel background tmp_*.gif
convert tmp_*.gif -loop 0 my_gif_rotated.gif
Hopefully this helps others.

Resize image based on memory size

I need to resize image based on memory.
What I am getting is following option in "convert" command.
-resize 800x600
-resize 25%
Is there any command like -
-resize 10KB
Thanks
Use this:
convert input.jpg -define jpeg:extent=300kb ... output.jpg
If you want a way to do something similar with Python, I wrote an answer that works pretty well here. It does a binary search for a JPEG quality that satisfies a maximum size requirement.

how to reduce the size with imagemagick when the original file is too big

I converted a 2.9M jpg to a 20x20 using 8 as the quality. but that file's size is still 48k.
here is my command
convert 238832c58dc3bc0b_29M.jpg -quality 8 -resize '20x20>' +repage 238832c58dc3bc0b_20x20.jpg
and after conveted, 238832c58dc3bc0b_20x20.jpg is 48k. I tried smalled size and quality, still 48k. it shouldn't be so big. it should be less than 10k. anybody know how to enhance it? thanks
Use -thumbnail instead of -resize or add -strip to your command.
Thumbnail removes the EXIF information apart from the color profile and strip removes the color profile as well.

How to pixelate/blur an image using ImageMagick?

I want to pixelate and/or blur an image.
I've found the command for the blurring:
$convert image.jpg -blur 18,5 newimage.jpg
to work but I cannot blur the image any more.
And how do I pixelate the image? I couldn't find a sound example around the net.
Thx
To get a proper square pixellation, try:
convert -scale 10% -scale 1000% original.jpg pixelated.jpg
This worked nicely for me, gives a sort of cross between pixelating and blurring:
convert -resize 10% image.jpg newimage.jpg
convert -resize 1000% newimage.jpg newimage.jpg
You can be sure that the data cannot be retrieved, should that be important to you.
Changing the %ages will change the amount of pixelation/blur
I don't know anything about ImageMagick, but you can try resizing the image using bicubic to a much smaller dimension, then resizing the image back to a bigger one.
The trick works using .net's System.Drawing object.

Resources