开发者

ImageMagick Gravity parameter

开发者 https://www.devze.com 2022-12-21 06:19 出处:网络
I\'m trying to create a process to automatically generate thumbnails of the images uploaded to my website.

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 mi开发者_如何转开发ssing something?

test input:

ImageMagick Gravity parameter

Result:

ImageMagick Gravity parameter


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

ImageMagick Gravity parameter


(source: datageist.com)

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号