Drevak
Drevak

Reputation: 867

ImageMagick Gravity parameter

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

Upvotes: 1

Views: 4899

Answers (2)

datageist
datageist

Reputation: 997

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.

Upvotes: 2

Drevak
Drevak

Reputation: 867

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

Upvotes: 0

Related Questions