Gimp-Forum.net
Resizing images into squares - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Resizing images into squares (/Thread-Resizing-images-into-squares)



Resizing images into squares - IAmFrenk - 02-09-2019

Hello everyone,

I was fiddling around with BIMP (Batch Image Manipulation Plugin) and I ran into a problem I couldn't solve.
I have a large amount of images that I want to make square.
Example: if an image is 500x700, it should be resized to 700x700, without stretching the image, and while keeping the image centered.

Anyone any idea how I can fix my problem?

Thanks in advance!

Cheers,
Frenk


RE: Resizing images into squares - rich2005 - 02-09-2019

(02-09-2019, 03:28 PM)IAmFrenk Wrote: Hello everyone,

I was fiddling around with BIMP (Batch Image Manipulation Plugin) and I ran into a problem I couldn't solve.
I have a large amount of images that I want to make square.
Example: if an image is 500x700, it should be resized to 700x700, without stretching the image, and while keeping the image centered.

Assuming you ran into problems because of a mixture of Portrait and Landscape aspect ratio images.

You can do this in BIMP but needs two operations because BIMP does not permit a duplicate resize.

You will be overwriting files so make sure you use copies (or be very confident in your own ability)

First Resize to fixed width with padding, but include a gimp operation 'zealouscrop' with the out folder set same as images.

[attachment=2606]

Apply this and the images are all the same width but various heights.

Do not leave BIMP, go and edit the procedures. Remove zealous crop. Edit Resize for a fixed Height with padding.

[attachment=2607]

Apply BIMP and that gets you all a defined width and height with appropriate padding depending on aspect.

Does not make sense? A short video demo, duration 2- 1/2 minutes.





direct link https://youtu.be/kTp-rbYQsQg


RE: Resizing images into squares - IAmFrenk - 02-11-2019

Hi rich2005,

First off, thank you for taking the time to write such a detailed explanation.
But sadly your answer does not seem solve my problem. I think I wasn't clear enough explaining the situation.
I have around 2000 images with different sizes. For example: one image can be 400x200, while another image is 25x50.
I am looking for a way to make all these images square. Going with the example: the first image should become 400x400, and the other image should become 50x50.

If you or anyone else has any idea how to solve this please let me know.

Cheers,
Frenk


RE: Resizing images into squares - rich2005 - 02-11-2019

A bit of a struggle for me. Nothing I can see using BIMP and nothing using the usual GUI batch utilities such as XNViewMP.

So down to ImageMagick, which is a command line utility see: http://www.imagemagick.org and the Windows Installer download is way down bottom of this page https://www.imagemagick.org/script/download.php

This is the code to run in a terminal, copy and paste into notepad

Code:
for /r %x in (*.jpg) do magick "%x" -gravity Center -background White -extent "%[fx:max(w,h)]x%[fx:max(w,h)]" "%x_square.jpg"

and if you are not used to using Windows Command terminal some hints here:





Direct link https://youtu.be/qkdup-cReiA  duration 2 minutes

Not much I can do about the naming convention, maybe some Windows expert can advise or use one of the several Windows renaming utilities.

-----

EDIT: I did not think that the magick command could overwrite existing files, but it does. You could try the slightly amended command

Code:
for /r %x in (*.jpg) do magick "%x" -gravity Center -background White -extent "%[fx:max(w,h)]x%[fx:max(w,h)]" "%x"

That will keep the same file names.
Dangerous. Same as BIMP, work with copies or you might lose the originals.


RE: Resizing images into squares - IAmFrenk - 02-11-2019

Hi rich2005,

Thanks a lot for your answer, this is exactly what I was looking for!

For anyone planning to use this; note that all the folders inside of the folder where you run the command get used as well.
Also know that you can type 'transparent' instead of 'White', which is what I used.

Once again thanks rich2005!

Cheers,
Frenk