Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Efficient Image Resizing with ImageMagick (smashingmagazine.com)
48 points by jschwartzi on Oct 27, 2015 | hide | past | favorite | 16 comments


> best results with Triangle also known as bilinear interpolation

Just no. Use bilinear only when you need very fast resizing and don't care about quality much. Lanczos and sinc [1] filters are considered "best" for wide range of images (no visible blurring or sharpening, almost no moire effects), but they are also among slower ones. Use Catmull-Rom when images need to be sharpened a bit. (See [2] for comparison and scripts) There's also faster and less buggy fork named GraphicsMagick [3]

[1] https://en.wikipedia.org/wiki/Sinc_filter

[2] http://www.dylanbeattie.net/magick/filters/result.html

[3] http://www.graphicsmagick.org/


I second GraphicsMagick over ImageMagick. In PHP found it performed especially well when executing through exec() rather than the extension.

See Gifsicle [1] for easy animated GIF resizing, which I found buggy in both IM and GM.

[1] https://www.lcdf.org/gifsicle/


Lanczos-2 is pretty much identical to Catmull-Rom, and Lanczos-3+ are all sharper than Catmull-Rom, but at the cost of ringing artifacts.


hello


Nicolas Robidoux has a page on advanced resizing techniques here: http://www.imagemagick.org/Usage/filter/nicolas/

Resizing in a sigmoidized colorspace has impressive results with many images. I find it works particularly well with images that should have been saved as vectors, especially when used with eliptical weighted average filters (-distort Resize). It significantly increases sharpness while causing artifacts that are difficult to notice because they don't look like any traditional image processing artifacts.

The same technique is also available in MPV for scaling video.


just curious - do you know of any way that will detect if images should probably have been saved in vector format - the detection should be reasonably performant so it isn't wasteful to check before deciding which optimizer to use.


Recent versions of Imagemagick support entropy measurement, which is typically lower in diagram/line art type images. You can check it with 'identify -format "%[entropy]" filename.png'. Some quick testing suggests photographic images usually measure greater than about 0.8.


Or you can use a service like https://www.imgix.com or https://www.filepicker.com and let them to the hard in real time.

That way if you want to change your image dimension later you don't have to go back and resize the images.


http://cloudinary.com is another good service.


So surprised whenever I hear about someone manually resizing their images like animals... imgix is fantastic


I puke a little inside my mouth whenever I see photographs ever decreasing in quality on the internet. Every time a picture gets uploaded, to for example Facebook, the quality decreases with roughly 40% in trade for a smaller file size. As those pictures often get reuploaded, you will quickly see exponential quality decrease. People write this off as "you can't see it!" but with ever increasing resolutions on smartphones, tablets and even monitors the decrease in quality of online photographs is getting painfully more evident. This is odd, given it's exactly the opposite with video. On YouTube you will hear outcries when a video isn't available in 1080p, yet with pictures people don't care if 70% of the detail is replaced with static noise.


I feel the same re: images of center aligned 'inspirational' text which I more artifact than original content.


Very nice article. It is nice to see photoshop-like capabilities added to web applications. Although, it seems a pain to use with various platforms, like Java, .NET ... image manipulation is needed depending on what device or connection speed the requester might be using. I would like non-camera pics to be vector based, to allow dynamic resizing. And camera photos should use this capabilities, along with a small link provided to download full quality photo, if needed. But these image manipulation capabilities should be part of a framework so that it is easier to use and update. After all, every page is littered with images, however, there is so little we can do with them right now. Good approach though to start of with ...


The author goes into great detail to explain the various idiotic ways you can use ImageMagick, which, at it's core, has a command line interface.

If you need to do any appreciable amount of work, don't waste your time with any of these libraries. Except for a few, they provide nothing over what running from the shell would give you (i.e. non-native). Just generate a list of commands, newline terminate them, add a chmod +x to the file and run it and be done with it. Or spawn a process and run it. It's much more reliable and will save you a lot of headaches and frustration.


Isn't there a lot of overhead to spawning a new process every time? I wonder what that cost is relative to the cost of generating the image.


I mean generating all your commands to a flatfile, then just execute the file via bash or similar.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: