M
M
Maxim Koreev2017-11-22 09:08:20
ImageMagick
Maxim Koreev, 2017-11-22 09:08:20

ImageMagik - how to make square images?

How to use mogrify to make all images square, and if they are large, then reduce them to 1000x1000 pixels? (and if they are smaller, then do not increase)
Now I do this: mogrify -geometry 1000x1000 -background white -extent 1000x1000 -gravity center *
In this case, small pictures are stretched to 1000x1000.
I would also like to process both jpg and png in one run, but in png you need to preserve transparency, and in jpg make the fill white. If you specify -background none, then in png everything is fine, but in jpg it fills with black.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Moskus, 2017-11-22
@Moskus

In general, I would do it through convert -resize. Accordingly, y -geometryhas suffixes < and > used in the form 1000x1000>, for example. This tells IM "don't increase anything less". Options are described here www.imagemagick.org/script/command-line-processing...
And you forgot -background whiteto add -compose Copy.
The complete code will look like this (some OSes will require you to escape the character >):
It is worth doing in two passes for PNG and JPEG separately, adding settings to the command for JPEG -qualityand -sampling-factor- there is nothing wrong with that. Don't forget, also, -stripto optimize if required.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question