ImageMagick Gravity Option

I am trying to create a process for automatically creating thumbnails of images uploaded to my site.

I use this command line:

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

The thumbnail is created without problems, with the right aspect ratio. but the -gravity center option doesn't seem to do anything, the actual image is always aligned to the left edge of the canvas when I want it to be centered ... Am I missing something?

test input:

alt text

Result:

alt text

+1
source share
2 answers

The convert.exe file has been updated with the latest version from www.imagemagick.org and ... tada! the problem is resolved.

0
source

If your source images have the same image format as your thumbnails, there is nothing to crop, and therefore -gravity seems to have no effect. For example, if you change -extent to 50x50, and then play with -gravity, you will see changes in alignment.

Edit (update for comments):

Here is 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 this helps, but it seems to work.

+2
source

Source: https://habr.com/ru/post/898252/


All Articles