最近爱摄影,电脑里很多照片。而且现在的相机拍出来都很大的尺寸,看看和传送都不方便。
一张张处理又麻烦,于是想写个程序来做。结果发现ImageMagick有个命令行的工具,就叫convert,于是就很方便的用shell写了个脚本。
注意:必须先安装ImageMagick sudo apt-get install imagemagick
resize_image.sh
CODE:
#!/bin/bash
# Used to resize the images
help_messge()
{
echo "Usage: resize_image -d <dir> -w <width> -h <height>"
echo "-d The directory contains the images"
echo "-w The width after convert"
echo "-h The height after convert"
exit 1
}
if [ $# -lt 6 ]
then
help_messge
fi
while getopts d:w:h: opt
do
case "$opt" in
d) dir="$OPTARG";;
w) w="$OPTARG";;
h) h="$OPTARG";;
esac
done
if [ -d $dir ]
then
cd $dir
ls *.jpg > filelist.$$
for image in $(cat filelist.$$)
do
echo "Convert file $image"
convert -resize "$w"x"$h" $dir/$image $dir/_$image
done
rm filelist.$$
nautilus $dir
else
echo "The directory $dir is not exist"
exit 1
fi当然还不是很严谨,但自己用用足够了,呵呵
[
本帖最后由 bigapple 于 2007-7-3 22:51 编辑 ]