2

I want to create thumbnails for all images of a folder. I also want the images to fit in a square of 100x100 pixels.

So after scaling the images down, while the smaller side needs to be 100 pixels, the larger side should be cropped so as to make it equal to 100.

With ImageMagick I have tried:

for i in $(ls *.jpg); do convert -scale 100 $i th-$i; done

It works but for an example image of 1000x800, the scaled down image has a size of 100x80 instead of 100x100.

0

Try this:

for i in $(ls *.jpg); do convert -resize 100x100^ -gravity center -crop 100x100+0+0 $i th-$i; done

You can find more examples of resizing and scaling here, " Resizing to Fill a Given Space" seems to be most relevant to your problem.

  • Thank you, but that didn't work. It just created some more images, but with their initial sizes. – user1170330 Jan 3 '16 at 17:50
  • Which version of ImageMagick are you using? Because Resizing to Fill a Given Space also mentions this: "As of IM v6.3.8-3 a new resize flag '^' will let you do this directly as a single resize step. These examples represent an alternative method that can be used for users with older versions of ImageMagick." – usmanayubsh Jan 3 '16 at 18:15
0

The following method may be helpful:

for i in *.jpg
do
convert "$i" -resize 100x100 -background white -compose Copy \
-gravity center -extent 100x100 "${i%.jpg}_thumb.jpg"
done

You should alter the background colour according to the background colour of your file manager...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.