본문 바로가기

Linux

해당 폴더의 이미지의 해상도 리사이즈를 50%로 줄이는 코드 imagemagic을 활용

해당 폴더의 이미지의 해상도 리사이즈를 50%로 줄이는 코드 imagemagic을 활용


$ for x in *.jpg;do
> convert -resize 50% "$x" "resized_$x";
> done

$ dpkg -S /usr/bin/convert
imagemagick: /usr/bin/convert

$ man convert
-resize geometry resize the image

http://www.imagemagick.org/script/comma ... p#geometry


if [ ! -e output ]; then
    mkdir output
fi

# 확장자가 JPG인 이미지를 800x600px로 리사이즈 하기
for img in *.JPG
do
    echo
"resizing $img ..."

    width
=`identify -ping $img | cut -f 3 -d " " | cut -f 1 -d "x"`
    height
=`identify -ping $img | cut -f 3 -d " " | cut -f 2 -d "x"`

   
if [ $width -gt $height ]; then
        convert
-resize 800x600 -unsharp 1.0x1.0+1.0 $img output/$img
   
else
        convert
-resize 600x800 -unsharp 1.0x1.0+1.0 $img output/$img
   
fi
done