Imagemagick convert with resample option

5,151

Have you taken a look at the general thumbnail section of the ImageMagick Usage site? It's quite good. The examples there typically use the thumbnail option. From Generate Thumbnails in General:

This not only resizes the image, but strips any and all profile and comment information that may be present in the original JPEG image. Also as it uses the "-sample" resize operator for the initial downsizing of the image, it is reasonably fast, and produces good results for small thumbnails.

Are you putting some kind of border around these images? Also, there is a 'new' geometry operator in IM, ^, the Fill Area Flag:

As of IM v6.3.8-3 IM now has a new geometry option flag '^' which is used to resize the image based on the smallest fitting dimension. That is, the image is resized to completely fill (and even overflow) the pixel area given.

So you might try:

convert FILE -thumbnail 64x64^ -gravity center -extent 64x64+0+16 -strip OUTFILE

Share:
5,151
coneybeare
Author by

coneybeare

Updated on September 17, 2022

Comments

  • coneybeare
    coneybeare over 1 year

    I am creating thumbnails from much larger images and have been using this command successfully for some time:

    convert FILE -resize "64x" -crop "64x64+0+16" +repage -strip OUTFILE
    

    I also do some other processing that is not relevant to the question. I realized that this does not adjust the resolution at all, so if I use a 300dpi image, it ends up displaying really small on some devices. I want to resample it to 72x72 so I have been trying with this command:

    convert FILE -resize "64x" -crop "64x64+0+16" +repage -strip -resample 72x72 OUTFILE
    

    And expected the 64x64 image at 300dpi to be resampled to a 64x64 image at 72dpi, but instead, I am getting a very funny size and density.



    Here is "identify" output for the original and post-processed file WITHOUT the resample:

    coneybeare $ convert "aa.jpg" -crop "64x64+0+16" +repage -strip "aa.png"
    coneybeare $ for image in `find . -type f`; do identify $image; identify -verbose $image | egrep "^  Resolution"; done
    ./aa.jpg JPEG 1130x1695 1130x1695+0+0 8-bit DirectClass 1.492MiB 0.000u 0:00.000
      Resolution: 300x300
    ./aa.png PNG 64x64 64x64+0+0 8-bit DirectClass 7.46KiB 0.000u 0:00.000
      Resolution: 118.11x118.11
    

    And here is the "identify output for the command WITH the resample:

    coneybeare $ convert "aa.jpg" -crop "64x64+0+16" +repage -strip -resample 72x72 "aa.png"
    coneybeare $ for image in `find . -type f`; do identify $image; identify -verbose $image | egrep "^  Resolution"; done
    ./aa.jpg JPEG 1130x1695 1130x1695+0+0 8-bit DirectClass 1.492MiB 0.000u 0:00.000
      Resolution: 300x300
    ./aa.png PNG 15x15 15x15+0+0 8-bit DirectClass 901b 0.000u 0:00.000
      Resolution: 28.34x28.34
    





    So, the question is: What am I doing wrong and how can I fix it so the end result is a 64x64 cropped thumbnail image at 72dpi?