this post was submitted on 13 Feb 2026
37 points (97.4% liked)

Linux

12303 readers
582 users here now

A community for everything relating to the GNU/Linux operating system (except the memes!)

Also, check out:

Original icon base courtesy of lewing@isc.tamu.edu and The GIMP

founded 2 years ago
MODERATORS
 

Hello everyone, does anyone know of a batch resizing tool on Linux that can resize loads of images all at once while keeping all the images the same aspect ratio as before? I would like to make all my images in a game have either a width of at least 128 px or height of 192 px (e.g. an image that is 700x875 would resize down to 154x192px, so that width is > 128 px and height = 192 px. I think for most of the images resizing based on height will work, but you never know!)

edit: I have used a for loop that cds into each directory, uses imagemagick to resize all of them to fill/overflow area 128x192 with ^ tag and using morgify to modify in place, then cd back to the parent directory! Thanks everyone

top 15 comments
sorted by: hot top controversial new old
[–] HaraldvonBlauzahn@feddit.org 1 points 8 hours ago* (last edited 8 hours ago)

You can simplify the for loop by something like

#!/bin/bash
shopt -s globstar             #assuming bash
for i in images/**/*.gif 
do
     convert ..... $f
done

or, if you don't use bash,

find images/ -type f -name '*.gif' -print0 | xargs -0 convert .... '{}' 
# maybe xargs needs "-1" option to process only one file at a time

both versions call imagemagick's convert on all files ending in .gif in the images folder.

For testing, put an "echo" command in front of the "convert" .

You could also check out if there are Rust utilities which do what you want - you'd need to install these using "cargo install".

[–] frongt@lemmy.zip 22 points 2 days ago (2 children)

https://usage.imagemagick.org/resize/

Imagemagick is very powerful and easy to use, but be aware that the syntax can be a bit arcane. You will need to use mogrify to modify in-place, and make sure you tell it to only resize if it's larger, and to preserve the aspect ratio. If you just tell it "resize everything to 192x128" it will do exactly that, regardless of the size or shape of the input image.

[–] sbeak@sopuli.xyz 6 points 2 days ago

The link you mentioned looks quite helpful, thanks! Imagemagick is pretty cool

[–] sbeak@sopuli.xyz 4 points 2 days ago* (last edited 2 days ago)

~~It looks like I need to use the "fill area" option, possibly with centering too.~~

~~nvm, read that option wrong. Only scale down it is then w/ keep aspect ratio~~

Never mind, I was right, I just found that the mogrify command requires the file name to be last

[–] commie@lemmy.dbzer0.com 9 points 2 days ago (1 children)

imagemagik can do it. but I think you're going to need a for loop to iterate through subdirectories

[–] sbeak@sopuli.xyz 2 points 2 days ago (1 children)

Will use a loop to go through the subdirectories then

[–] Successful_Try543@feddit.org 3 points 2 days ago* (last edited 2 days ago)

@commie@lemmy.dbzer0.com

You may use find with the -exec option or xargs depending on whether imagemagick reads from standard input or doesn't.

[–] pcouy@lemmy.pierre-couy.fr 4 points 2 days ago (1 children)

ImageMagick does the job but can be slow. libvips is à faster alternative

[–] rbos@lemmy.ca 2 points 2 days ago (1 children)

Well, this is exactly what I needed for work... we process like 200MB tiffs and imagemagick speed and mem use is an issue

[–] pcouy@lemmy.pierre-couy.fr 2 points 1 day ago* (last edited 1 day ago) (1 children)

I found out about it while making a Jekyll plugin, the speed improvement is really noticeable

[–] rbos@lemmy.ca 1 points 1 day ago

Yeah, I tested it on some large TIFF datasets I have around. 3x less memory and 4x faster.

[–] BigTrout75@lemmy.world 4 points 2 days ago

Imagemagick with bash script. Lookup how to run a bash script recursively through sub folders

[–] TheKracken@lemmy.world 3 points 2 days ago
[–] Maiq@piefed.social 3 points 2 days ago

Dont know if this is what you are looking for. I have never used it as I just write a quick python script, but I hope this helps.

https://github.com/Nenotriple/batch_resize_images

[–] pglpm@lemmy.ca 2 points 2 days ago* (last edited 2 days ago)

Take a look at XnView, it has batch capabilities of that kind, which you can set up through a graphical interface. Ships for linux too.