In my Ubuntu server, I have a specific directory that contains a large number of images that I wish to resize to a width of 2000px if they are larger than 2000 pixels whilst maintaining their aspect ratio but if an image's width is less than 2000px it shall remain unchanged.
I want to edit the original image and not make a copy and I have no GUI installed on my server.
You might want to use ImageMagick. It isn't included in the default installations of Ubuntu and many other Linux distributions, so you will have to install it first. Use the following command:
sudo apt-get install imagemagick
You can specify a width (or height) and ImageMagick will resize the image for you while preserving the aspect ratio.
The following command will resize an image to a width of 2000:
convert example.png -resize 2000 example.png
There is also an option so that it will only shrink images to fit into the given size. It won't enlarge images that are smaller. This is the '>' resize option. Think of it only applying the resize to images 'greater than' the given size, the syntax might be a little counter-intuitive.
convert example.png -resize 2000\> example.png
You can use bash
to apply the command to all of your images,
for file in *.png; do convert $file -resize 2000\> $file; done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With