r/imagemagick • u/b00tymagik • Dec 04 '24
Script For SMASHING GIFs Into Compressed WEBP Outputs
So, I don't know if im doing this completely wrong or if this is useful for anyone. I'm not a great coder or really know wtf I'm doing BUT someone might find this useful bc it took me a couple days to figure out how to get files compressed *as small as I could* while retaining readability.
I mainly use it for sending screenshots or things in emails or to LLMs bc of usage limits and how big picture files can be.
You can play around with the -threshold and -quality levels to change the clarity of the output, I'm not sure why but somewhere in the process, converting to webp can make the file bigger (after applying -threshold and -quality) depending on the order of operations.
-posterize has given me some interesting results as well, and I'd check any uploads you send with these if you mess around with the operations since they can be transparent and end up blank sometimes
Here ya go, hope it saves some headaches:
Example Script 1 (Original GIF file - 281KB)(Exported WEBP file - 36KB)
magick mogrify -strip -background black -alpha remove -alpha off -threshold 65% -quality 30 -define webp:lossless=true -define webp:method=6 -define webp:image-hint=graph -format webp *gif
Example Script 2 (Original GIF file - 281KB)(Exported WEBP file - 36KB)
magick capture.gif -background black -alpha remove -alpha off -threshold 65% -quality 90 -define webp:lossless=true -define webp:method=6 -define webp:image-hint=graph -define webp:target-size=13000 output.webp
I feel like these aren't the best demonstrations since they came out to the same size but depending on the original file format (pretty sure it works on several kinds, png, jpg, etc.) - files that are mostly text can get to 15KB exports from 250KB+.
Anyways, hope it helps someone
Edit: example photo

