Live data from Hacker News

Using ImageMagick to make sharp web-sized photographs

even.li

51–60 of 64 posts

Re: Using ImageMagick to make sharp web-sized photographs

#51
Could also be useful to downscale images using the 'high contrast downscale' filter (as we call it in our lab; maybe this isn't the common name). For each set of pixels to become one, you compute min, max and mean, and select the one of {min, max} which is closer to mean.

Unfortunately, I don't have any examples handy.

Re: Using ImageMagick to make sharp web-sized photographs

#52
post #48

Dissecting a bad oneliner: ls *.jpg|while read i;do gm convert $i -resize "900x" -unsharp 2x0.5+0.5+0 -quality 98 `basename $i .jpg`_s.jpg;done The part I take issue with is the unnecessary invocation of `ls`. The shell does the glob expansion. A `for` loop is better suited for this. Also, if using bash,* we can get rid of basename. for file in *.jpg; do gm convert $file -resize "900x" -unsharp 2x0.5+0.5+0 -quality 9…

sysadmin...sense...tingling...

Get in the habit of putting $file (and, in this case, ${file%.jpg}_s.jpg) in double quotes. Your one-liner (and theirs) will blow up spectacularly if there's whitespace in a filename:

    bash-3.2$ for i in 'lots       of spaces'.jpg '1 2'.jpg; do printf 'arg = %s\n' ${i%.jpg}_s.jpg; done
    arg = lots
    arg = of
    arg = spaces_s.jpg
    arg = 1
    arg = 2_s.jpg

    bash-3.2$ for i in 'lots       of spaces'.jpg '1 2'.jpg; do printf 'arg = %s\n' "${i%.jpg}_s.jpg"; done
    arg = lots       of spaces_s.jpg
    arg = 1 2_s.jpg
EDIT: It's also worth noting that, by default, zsh doesn't split on whitespace in parameter expansion like sh, bash, etc. do. ("man zshexpn" and search for "SH_WORD_SPLIT")

Re: Using ImageMagick to make sharp web-sized photographs

#53
post #48

Dissecting a bad oneliner: ls *.jpg|while read i;do gm convert $i -resize "900x" -unsharp 2x0.5+0.5+0 -quality 98 `basename $i .jpg`_s.jpg;done The part I take issue with is the unnecessary invocation of `ls`. The shell does the glob expansion. A `for` loop is better suited for this. Also, if using bash,* we can get rid of basename. for file in *.jpg; do gm convert $file -resize "900x" -unsharp 2x0.5+0.5+0 -quality 9…

As long as we're bashing, it could easily be written loopless like so:

    basename -s .jpg -a *jpg | 
      xargs -I{} convert "{}.jpg" \
       -resize "900x" -unsharp 2x0.5+0.5+0 -quality 98 "{}_s.jpg"
EDIT: weird line breaking is to prevent sidescroll box

Re: Using ImageMagick to make sharp web-sized photographs

#54

mod_pagespeed (and ngx_pagespeed) can automate this for all your images. If you have inline width/height or inline style dimensions, it will do the resampling on your behalf: https://developers.google.com/speed/pagespeed/module/filter-... The advantages of having correctly sized imagery are immense, but in short.. something like 70% smaller total byte payload for mobile, huge reduction in image decode & resize cost,…

where are the resizes stored when this directive is used?

   > pagespeed EnableFilters resize_images;

Re: Using ImageMagick to make sharp web-sized photographs

#55
post #48

Dissecting a bad oneliner: ls *.jpg|while read i;do gm convert $i -resize "900x" -unsharp 2x0.5+0.5+0 -quality 98 `basename $i .jpg`_s.jpg;done The part I take issue with is the unnecessary invocation of `ls`. The shell does the glob expansion. A `for` loop is better suited for this. Also, if using bash,* we can get rid of basename. for file in *.jpg; do gm convert $file -resize "900x" -unsharp 2x0.5+0.5+0 -quality 9…

As long as we're bashing , it could easily be written loopless like so: basename -s .jpg -a *jpg | xargs -I{} convert "{}.jpg" \ -resize "900x" -unsharp 2x0.5+0.5+0 -quality 98 "{}_s.jpg" EDIT: weird line breaking is to prevent sidescroll box

You could also easily parallelize this with xargs' -P option.

Re: Using ImageMagick to make sharp web-sized photographs

#56

mod_pagespeed (and ngx_pagespeed) can automate this for all your images. If you have inline width/height or inline style dimensions, it will do the resampling on your behalf: https://developers.google.com/speed/pagespeed/module/filter-... The advantages of having correctly sized imagery are immense, but in short.. something like 70% smaller total byte payload for mobile, huge reduction in image decode & resize cost,…

where are the resizes stored when this directive is used? > pagespeed EnableFilters resize_images;

Probably /var/mod_pagespeed/cache, though I don't have it installed right now to check.

Re: Using ImageMagick to make sharp web-sized photographs

#57
post #40

ImageOptim has been my best buddy, been getting very agreeable results with it. It's just for compression but end results don't seem to have the need for sharpening. Using ImageMagick this way might be best for special cases... http://imageoptim.com/

ImageOptim is not just for compression, it is for stripping away useless metadata, color palettes and other tricks. For optimal images, you could do something like this: 1) Resize the image (And apply the trick from this article) use the proper quality marker (anywhere between 85-95) 2) Run it through Imageoptim If you want a commandline version of ImageOptim, I have had good results with https://github.com/toy/image…

ah.. right on. cheers!

Re: Using ImageMagick to make sharp web-sized photographs

#58
post #22

For my games, I found out that the best thing when scaling is use IM Lancsoz filter. Granted, my games use high-res hand-drawn vector-ish art (not pixel art, neither photo-style or paint-style art) so I dunno if this is applicable to photos.

Imagemagick already uses a Lanczos resampling filter when downsampling. Lanczos inherently preserves sharp transient data, e.g., sharp edges in images, but it looks like the author wanted something more.

Re: Using ImageMagick to make sharp web-sized photographs

#60
post #6

Part of the reason rescaled images look dim and blurry is because rescaling software usually assumes gamma 1.0 instead of 2.2: http://www.4p8.com/eric.brasseur/gamma.html There are many more good essays on image rescaling here: http://entropymine.com/imageworsener/

Another issue is one needs to use a sharp filter during the resize, like sinc or something. Then post sharpening is not required in the first place.
Post reply on HN