Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to batch resize images in Ubuntu recursively within the terminal?

I have multiple images stored in a set of organized folders. I need to re-size those images to a specific percentage recursively from their parent directory. I am running Ubuntu 11.10 and i prefer learning how to do that directly from the terminal.

like image 945
CompilingCyborg Avatar asked May 29 '12 15:05

CompilingCyborg


People also ask

How do I resize an image in Ubuntu terminal?

If you are using Fedora, Arch, or other non-Debian Linux, you can use your distribution's package installing command. Now if you right click on an image, you'll see two new options of resizing and rotating in the context menu. You can choose the resize option to resize the image right from the right-click menu quickly.

Can you resize images in bulk?

Select a group of images with your mouse, then right-click them. In the menu that pops up, select “Resize pictures.” An Image Resizer window will open. Choose the image size that you want from the list (or enter a custom size), select the options that you want, and then click “Resize.”


1 Answers

You could use imagemagick. For instance, for resizing all the JPG images under the current directory to 50% of their original size, you could do:

for f in `find . -name "*.jpg"` do     convert $f -resize 50% $f.resized.jpg done 

The resulting files will have ".jpg" twice in their names. If that is an issue, you can check the following alternatives.

For traversing/finding the files to resize, you can use xargs too. Example:

find . -name "*.jpg" | xargs convert -resize 50% 

This will create copies of the images. If you just want to convert them in place, you can use:

find . -name "*.jpg" | xargs mogrify -resize 50% 
like image 143
betabandido Avatar answered Sep 24 '22 14:09

betabandido