I'm using GIMP to do a simple but tedious operation for many images so I'd like to know how I can make a script that will do it for me, or find some simpler way of doing this.
I import an image file that has large dimensions but is mostly square, sometimes like 550x564, 580x596, etc., which may be jpg, bmp, or png, and I want to export a 192x192 PNG file, resized and cropped on both ends of the longer dimension, which is usually vertical but can be horizontal.
I perform the following steps for an image that is longer vertically than it is horizontally:
How can I do this in script-fu or python for GIMP? Or in ImageMagick? Or is there a better way of making a macro for this?
I think I understood you. Try this with ImageMagick to convert a single image:
convert input.jpg -gravity center -resize 192x192^ -extent 192x192 -set filename:base "%[basename]" "%[filename:base].png"
You could also potentially leverage the power of mogrify
to do a whole directory full of images in one go, but be very careful, and try it out on a COPY of your files somewhere away from your main work. That will actually be easier, because you can let mogrify
work out the filenames itself and you don't need a loop:
# Process all JPEGs in current directory
mogrify -format png -gravity center -resize 192x192^ -extent 192x192 *jpg
If you are on Windows, you may need to escape the caret (^
), I don't use Windows, but I think you will either need to add an extra caret before it, or maybe enclose the whole -resize
parameter in double quotes:
mogrify ... -resize "192x192^" ...
Note that if you are on ImageMagick v7+, mogrify ...
becomes magick mogrify ...