5/21/2023 0 Comments Gifsicle resize blurryAlso, as with any media meant to convey meaning on the web, please make sure you’re including relevant alternative text. A page full of gifs can make even a beefy computer or device strain itself, so just because you can bombard your users with animations doesn’t mean that you should (at least, if you care about user experience). The smaller you go, the harder Gifsicle has to work to round everything out in fact, you may find that gifs with smaller dimensions sometimes carry a larger filesize.įinally, I’ll remind you that while gifs can be a lot of fun, they’re not always the best way to convey a message. 500×280 instead of 500×281) tend to resize much cleaner and with less distortion. In my testing, I’ve found that gifs with even dimensions (e.g. You may also notice that there was some rounding going on, even in my examples. gifsicle -b -unoptimize -O2 anim.gif -replace 1 x.gif -unoptimize is used since anim.gif was optimized in the last step. You may have noticed there’s a bit of math involved with resizing images it’s nothing that requires an advanced degree, but it’s still not how I’d like to spend my afternoon. Even if you’re not using WordPress, I’d encourage you to look at the image_resize_dimensions() function and how it’s implemented this is a geometry problem that’s been solved before, so there’s no need to reinvent the wheel. Now that we have the hard-coded version, we’ll break this up into placeholders ( using proper escaping for shell arguments, of course) and we’ll find ourselves with the full, variable-filled version we had before! Gotchas With these numbers at hand, we can ask Gifsicle to resize our image to 267×150: Once you have installed it you can use the lossey option as below gifsicle -O3 -lossy80 gifimage1.gif -o new-gifimage1. Given the height, we can calculate the width thusly: $src_width / $src_height * $dst_height, or 500 / 281 * 150, which gives us a width of 267px. If you want to enable lossy compression which reduces the size considerably, you can use giflossy fork of gifsicle. Installation: On Mac : brew install giflossy. gifsicle -O3 -lossy80 gifimage1.gif -o new-gifimage1.gif. Once you have installed it you can use the lossey option as below. Confused? Just remember that we have a 16:9 aspect ratio, meaning the height is the smaller dimension and thus cannot end up smaller than 150px or we risk our 150×150 frame not being filled. If you want to enable lossy compression which reduces the size considerably, you can use giflossy fork of gifsicle. Now, let’s say we want a square version of that same image, at 150×150. In order to achieve this, we need to perform two operations: resizing the image to fit as much of it as possible into a 150×150 box, then crop off anything outside that area.įortunately, resizing the image is easy: Gifsicle has a -resize option, and the math that led us to our getimagesize()-compatible calculations up above would tell us that to fit a 500×281 image in a 150×150 box, our target dimensions would be 267×150. The original dimensions of this image are 500×281, approximately a 16:9 aspect ratio. Next to the sliding scale, you can enter in a numerical value to adjust the sharpening effect. Unblur your images now Unblur an image with precision. Select the Enhancements option and then use the Sharpen sliding scale to unblur your image. You may also try to generate new palette for each frame, so you can skip the first pass, and use the new option in the paletteuse filter.Well, that was easy, wasn’t it? In case you’re not well-versed in juggling arguments and using PHP to assemble CLI commands, we’ll apply some real numbers: let’s say we have this gif of America’s Sweetheart, Nick Offerman: Open your image in the editor, then tap or click on it to open the image editing menu. gifsicle -resize-width 600 helm-org-clock.gif -o hoc-smaller. ![]() You might need to fiddle with the params and the dithering methods to achieve best result. Below is my command, taught by askubuntu. Then, use this color template to generate the actual gif file: ffmpeg -i -i palette.png -filter_complex "fps=10 scale=500:-1:flags=lanczos paletteuse=dither=sierra2_4a" -t 10 ![]() On the other side, you can achieve better results with ffmpeg only.įirst, I'd generate a palette of the input video: ffmpeg -i -filter_complex "fps=10 scale=500:-1:flags=lanczos,palettegen=stats_mode=full" -t 10 palette.png (Also, there's no such things like "huge" pixels, they are the atomic elements of raster images.) For best results, I'd recommend floyd_steinberg or sierra2_4a, and maybe bayer with scale set to 3. I suppose you have no imageMagick installed on your environment, because "convert" is one of IM's tools.Īs for the video artifacts, it is caused by the default dithering method in FFmpeg. Shell_exec("/usr/bin/ffmpeg -i video.mkv -r 20 -f image2pipe -vcodec ppm - | convert -delay 5 - output.gif")
0 Comments
Leave a Reply. |