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

猜你喜欢

转载自sillycat.iteye.com/blog/972338