Resize images in directory

前端 未结 6 2087
半阙折子戏
半阙折子戏 2021-02-03 14:41

I have a directory full of images that I would like to resize to around 60% of their original size.

How would I go about doing this? Can be in either Python or Perl

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-03 15:04

    Can it be in shell?

    mkdir resized
    for a in *.jpg; do convert "$a" -resize 60% resized/"$a"; done
    

    If you have > 1 core, you can do it like this:

    find . -maxdepth 1 -type f -name '*.jpg' -print0 | xargs -0 -P3 -I XXX convert XXX -resize 60% resized/XXX
    

    -P3 means that you want to resize up to 3 images at the same time (parallelization).

    If you don't need to keep originals you can use mogrify, but I prefer to use convert, and then rm ...; mv ... - just to be on safe side if resizing would (for whatever reason) fail.

提交回复
热议问题