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

前端 未结 6 1375
栀梦
栀梦 2020-12-23 10:15

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

6条回答
  •  庸人自扰
    2020-12-23 10:17

    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%
    

提交回复
热议问题