Shell脚本批量修改图片尺寸

 1 #!/bin/sh
 2 function scandir(){
 3     local cur_dir parent_dir workdir
 4     workdir=$1
 5     cd ${workdir}
 6     if [ ${workdir} = "/" ]
 7     then
 8         cur_dir=""
 9     else
10         cur_dir=$(pwd)
11     fi
12 
13     for dirlist in $(ls ${cur_dir})
14     do
15         if test -d ${dirlist};then
16             cd ${dirlist}
17             scandir ${cur_dir}/${dirlist}
18             cd ..
19         elif [[ "$dirlist" == *phone* ]];then 
20             ls  ${cur_dir}/${dirlist}
21             convert "${cur_dir}/${dirlist}"  -resize 600x600 "${cur_dir}/${dirlist}"
22         fi
23     done
24 }
25 
26 if test -d $1
27 then
28         scandir $1
29 elif test -f $1
30 then
31         echo "you input a file but not a directory,please reinput and try again ."
32 else
33         echo "the directory isn't exist which you input,please input a new one !"
34 fi

修改图片尺寸是用的ImageMagic工具

相关参考资料:

1、ImageMagic Convert 命令

2、Imagemagick中图片大小转换全攻略

3、String contains in bash

4、shell脚本遍历目录及其下子目录

posted @ 2013-10-14 14:52  易木  阅读(1447)  评论(0编辑  收藏  举报