Manage Picture on Ubuntu System

Manage Picture on Ubuntu System

These days, I have a lot of photos with large size on my computer. I need to deal with that and post
them to my blog. So, I will change the size from large to small, first.

First of all, I install the image tool
>sudo apt-get install imagemagick

Transfer the picture data files to jpg format
>convert $img $_basefullname;

We can write a shell to do this
>vi transpic.sh
#!/bin/sh
for img in `find ./ -name "*.[bB][mM][pP]"`; do
#change upper filename to lower
_imglower=`echo $img|tr "[:upper:]" "[:lower:]"`;
#get file's basename
_basename=`basename $_imglower .bmp`;
#get file's dir
_dirname=`dirname $img`;
#get desc filename with path
_basefullname=$_dirname"/"$_basename".jpg";
#do convert
convert $img $_basefullname;
#remove bmp file
rm $img;
echo "deal $_basefullname successfully";
done

Resize and change quality of the picture
>convert -resize 35%*35% -quality 20 $img $img-resized;

We can provide a shell to do this
>vi 50zippic.sh
for img in `find ./ -name "*.[jJ][pP][gG]"`; do
convert -resize 35%*35% -quality 20 $img $img-resized;
rm $img;
mv $img-resized $img
echo $img
done
for img in `find ./ -name "*.[pP][nN][gG]"`; do
convert -resize 35%*35% -quality 20 $img $img-resized;
rm $img;
mv $img-resized $img
echo $img
done
for img in `find ./ -name "*.[gG][iI][fF]"`; do
convert -resize 35%*35% -quality 20 $img $img-resized;
rm $img;
mv $img-resized $img
echo $img
done

Give the rights to execute these shell:
luohua@luohua-Vostro-3400:~$ chmod +x zippic.sh
luohua@luohua-Vostro-3400:~$ chmod +x transpic.sh

Copy the shell files to bin directory.
luohua@luohua-Vostro-3400:~$ sudo cp zippic.sh /bin
luohua@luohua-Vostro-3400:~$ sudo cp transpic.sh /bin

It is done. You can run this commands in your picture direcories.

references:
http://edu.codepub.com/2011/0320/30246.php
http://linux.chinaitlab.com/administer/771317.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值