1

I'm trying to create a process to automatically generate thumbnails of the images uploaded to my website.

I'm using this command line:

-thumbnail "120x90>" -quality 95 -background transparent -gravity Center -extent 120x90 img.png

The thumbnail is generated without problems, with the correct aspect ratio. but the option -gravity center seems that is doing nothing, the actual image is always aligned to the left of the canvas, when i want it centered...Am i missing something?

test input:

alt text

Result:

alt text

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Drevak
  • 867
  • 3
  • 12
  • 26

2 Answers2

2

If your source images have a similar aspect ratio to your thumbnails, there may be nothing to crop, and that's why it doesn't seem like -gravity is having any effect. For example, if you change -extent to 50x50, then play with -gravity, you'll see changes in the alignment.

Edit (update for comments):

Here's the result I got using this command-line with your sample image:

convert.exe -thumbnail "120x90>" -quality 95 -background transparent -gravity Center -extent 120x90 monalisa171p.jpg monalisa171p_thumb.jpg

alt text
(source: datageist.com)

I don't know if that helps, but it seems to work.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
datageist
  • 999
  • 6
  • 17
  • I'm using a 337x500px image for testing. The result is a 120x90 px image with all the right-side filled with blank pixels. The entire image is a aligned to left. – Drevak Feb 21 '10 at 15:16
  • updated with and example. You will see that the image is not centered on the canvas, but aligned to the left. – Drevak Feb 21 '10 at 15:23
0

Updated the convert.exe with the latest release from www.imagemagick.org and...tada! problem solved.

Drevak
  • 867
  • 3
  • 12
  • 26