# convert_and_compress v0.02en made under debian lenny/sid using vim 7.1 # # a very simple script that converts pictures and compress them with zip # author:krzysztof szynter aka dygi gg:1027078 email:k.szynter@gmail.com # # all rights are not reserved - copying modificating and using # are allowed but only for your own sole responsibility -------------------------------------------------------------------------------- dygi@orion:~/test$ su -c 'apt-get install imagemagick zip unzip' -------------------------------------------------------------------------------- dygi@orion:~/test$ dpkg --list | grep ' zip ' && dpkg --list | grep ' imagemagick ' ii imagemagick 7:6.2.4.5.dfsg1-1 Image manipulation programs ii zip 2.32-1 Archiver for .zip files ii unzip 5.52-10 De-archiver for .zip files -------------------------------------------------------------------------------- dygi@orion:~/test$ ls -Al -rwxr-xr-x 1 dygi dygi 5368 2007-07-29 10:24 convert_and_compress_desc_en -rwxr-xr-x 1 dygi dygi 916002 2007-07-29 01:24 p7220156.JPG -rwxr-xr-x 1 dygi dygi 913534 2007-07-29 01:24 p7220157.JPG -rwxr-xr-x 1 dygi dygi 915862 2007-07-29 01:24 p7220158.jpg -rwxr-xr-x 1 dygi dygi 885128 2007-07-29 01:24 p7220159.jpg -rwxr-xr-x 1 dygi dygi 888355 2007-07-29 01:24 p7220160.jpg -------------------------------------------------------------------------------- dygi@orion:~/test$ ./convert_and_compress_v0.02en - convert to mid and low res files [y/n]: y - compress mid and low res files with zip [y/n]: y - clean the mess in folder tree after all [y/n]: y Counting graphic files in folder [OK] :: 5 files Creating folder ./temp [OK] Copying *.jpg files into folder ./temp [OK] :: 3 files Copying *.JPG files into folder ./temp [OK] :: 2 files Changing working folder to ./temp [OK] Starting *.jpg convertion phase [OK] Starting *.JPG convertion phase [OK] Changing the original filenames to hires [OK] Starting compression phase 1) compressing lowres files [OK] 2) compressing midres files [OK] 3) compressing hires files [OK] Starting cleaning phase [OK] SUMMARY: There was no errors during the program work.. -------------------------------------------------------------------------------- dygi@orion:~/test$ ls -Al -rw-r--r-- 1 root root 4449882 2007-07-29 14:17 compressed_hires.zip -rw-r--r-- 1 root root 493949 2007-07-29 14:17 compressed_lowres.zip -rw-r--r-- 1 root root 807420 2007-07-29 14:17 compressed_midres.zip -rwxr-xr-x 1 dygi dygi 5026 2007-07-29 13:47 convert_and_compress_v0.02en -rwxr-xr-x 1 dygi dygi 916002 2007-07-29 01:24 p7220156.JPG -rwxr-xr-x 1 dygi dygi 913534 2007-07-29 01:24 p7220157.JPG -rwxr-xr-x 1 dygi dygi 915862 2007-07-29 01:24 p7220158.jpg -rwxr-xr-x 1 dygi dygi 885128 2007-07-29 01:24 p7220159.jpg -rwxr-xr-x 1 dygi dygi 888355 2007-07-29 01:24 p7220160.jpg -------------------------------------------------------------------------------- dygi@orion:~/test$ unzip compressed_lowres.zip Archive: compressed_lowres.zip inflating: lowres_p7220156.JPG inflating: lowres_p7220157.JPG inflating: lowres_p7220158.jpg inflating: lowres_p7220159.jpg inflating: lowres_p7220160.jpg -------------------------------------------------------------------------------- dygi@orion:~/test$ unzip compressed_midres.zip Archive: compressed_midres.zip inflating: midres_p7220156.JPG inflating: midres_p7220157.JPG inflating: midres_p7220158.jpg inflating: midres_p7220159.jpg inflating: midres_p7220160.jpg -------------------------------------------------------------------------------- dygi@orion:~/test$ unzip compressed_hires.zip Archive: compressed_hires.zip inflating: hires_p7220156.JPG inflating: hires_p7220157.JPG inflating: hires_p7220158.jpg inflating: hires_p7220159.jpg inflating: hires_p7220160.jpg -------------------------------------------------------------------------------- dygi@orion:~/test$ ls -Al -rw-r--r-- 1 root root 4449882 2007-07-29 14:17 compressed_hires.zip -rw-r--r-- 1 root root 493949 2007-07-29 14:17 compressed_lowres.zip -rw-r--r-- 1 root root 807420 2007-07-29 14:17 compressed_midres.zip -rwxr-xr-x 1 dygi dygi 5026 2007-07-29 13:47 convert_and_compress_v0.02en -rwxr-xr-x 1 dygi dygi 916002 2007-07-29 14:17 hires_p7220156.JPG -rwxr-xr-x 1 dygi dygi 913534 2007-07-29 14:17 hires_p7220157.JPG -rwxr-xr-x 1 dygi dygi 915862 2007-07-29 14:17 hires_p7220158.jpg -rwxr-xr-x 1 dygi dygi 885128 2007-07-29 14:17 hires_p7220159.jpg -rwxr-xr-x 1 dygi dygi 888355 2007-07-29 14:17 hires_p7220160.jpg -rw-r--r-- 1 dygi dygi 107040 2007-07-29 14:17 lowres_p7220156.JPG -rw-r--r-- 1 dygi dygi 105291 2007-07-29 14:17 lowres_p7220157.JPG -rw-r--r-- 1 dygi dygi 105531 2007-07-29 14:17 lowres_p7220158.jpg -rw-r--r-- 1 dygi dygi 115472 2007-07-29 14:17 lowres_p7220159.jpg -rw-r--r-- 1 dygi dygi 106677 2007-07-29 14:17 lowres_p7220160.jpg -rw-r--r-- 1 dygi dygi 172248 2007-07-29 14:17 midres_p7220156.JPG -rw-r--r-- 1 dygi dygi 169034 2007-07-29 14:17 midres_p7220157.JPG -rw-r--r-- 1 dygi dygi 169297 2007-07-29 14:17 midres_p7220158.jpg -rw-r--r-- 1 dygi dygi 179350 2007-07-29 14:17 midres_p7220159.jpg -rw-r--r-- 1 dygi dygi 164971 2007-07-29 14:17 midres_p7220160.jpg -rwxr-xr-x 1 dygi dygi 916002 2007-07-29 01:24 p7220156.JPG -rwxr-xr-x 1 dygi dygi 913534 2007-07-29 01:24 p7220157.JPG -rwxr-xr-x 1 dygi dygi 915862 2007-07-29 01:24 p7220158.jpg -rwxr-xr-x 1 dygi dygi 885128 2007-07-29 01:24 p7220159.jpg -rwxr-xr-x 1 dygi dygi 888355 2007-07-29 01:24 p7220160.jpg -------------------------------------------------------------------------------- dygi@orion:~/test$ more ./convert_and_compress_v0.02en #!/bin/bash # convert_and_compress v0.02en made under debian lenny/sid using vim 7.1 # # a very simple script that converts pictures and compress them with zip # author:krzysztof szynter aka dygi gg:1027078 email:k.szynter@gmail.com # # all rights are not reserved - copying modificating and using # are allowed but only for your own sole responsibility # ======================================================================================================= # description # a very simple script that converts pictures in ./ to lower resolution and compress them with zip # it works on a copy of files, not on the original files, has three switches to choose at the beginning # - convert phase [y/n] :: goes on or shows the summary and exits # - compress phase [y/n] :: compress each resoultion group of files into a separate zip file or do nth # - clean the mess [y/n] :: cleans the mess executing `rm -rf ./temp` or do nth # # if all options switched to 'y' the program creates the ./temp folder, copies the graphic files it found # to the ./temp, converts files to mid and low resolution files, changes the original filenames to hires, # compress each resolution group of files to a separate zip file, moves them ../ and remove a whole ./temp # so at the end you have 3 more files in ./ (zipped: low, mid and the original-hi res graphic files) # # limitations # - only .jpg and .JPG files for a while ! have to add other formats 'convert' allows # ======================================================================================================= # CONST LOW_RES_MODE='800x600' MID_RES_MODE='1024x768' # VAR error_status='0' # main program clear echo -en "- convert to mid and low res files [y/n]: " read convert_status if [ "$convert_status" = 'y' ] then echo -en "- compress mid and low res files with zip [y/n]: " read compress_status echo -en "- clean the mess in folder tree after all [y/n]: " read clean_status fi #echo -ne "\nPress ENTER to continue: " #read echo -en "\nCounting graphic files in folder " jpg_files_cnt=`ls -1 *.jpg | wc -l` JPG_files_cnt=`ls -1 *.JPG | wc -l` graphic_files_sum_cnt=$(($jpg_files_cnt+$JPG_files_cnt)) if [ "$jpg_files_cnt" -ge '1' ] then files_cnt='0' for i in `ls -1 *.jpg`; do files_cnt="$(($files_cnt+1))"; arr_files_jpg[$(($files_cnt))]="$i"; done fi if [ "$JPG_files_cnt" -ge '1' ] then files_cnt='0' for i in `ls -1 *.JPG`; do files_cnt="$(($files_cnt+1))"; arr_files_JPG[$(($files_cnt))]="$i"; done fi echo -en " [OK] :: $graphic_files_sum_cnt files\n" if [ "$convert_status" = 'y' ] then echo -n 'Creating folder ./temp ' mkdir ./temp && echo ' [OK]' if [ "$jpg_files_cnt" -ge '1' ] then echo -n 'Copying *.jpg files into folder ./temp ' cp ./*.jpg ./temp && echo -e " [OK] :: $jpg_files_cnt files" fi if [ "$JPG_files_cnt" -ge '1' ] then echo -n 'Copying *.JPG files into folder ./temp ' cp ./*.JPG ./temp && echo -e " [OK] :: $JPG_files_cnt files" fi echo -n 'Changing working folder to ./temp ' cd ./temp && echo -e " [OK]\n" echo -ne "Starting *.jpg convertion phase " if [ "$jpg_files_cnt" -ge '1' ] then for i in `seq 1 ${#arr_files_jpg[*]}` do convert "${arr_files_jpg[$i]}" -resize "$MID_RES_MODE" "midres_${arr_files_jpg[$i]}" convert "midres_${arr_files_jpg[$i]}" -resize "$LOW_RES_MODE" "lowres_${arr_files_jpg[$i]}" done fi echo -e " [OK]" echo -ne "Starting *.JPG convertion phase " if [ "$JPG_files_cnt" -ge '1' ] then for i in `seq 1 ${#arr_files_JPG[*]}` do convert "${arr_files_JPG[$i]}" -resize "$MID_RES_MODE" "midres_${arr_files_JPG[$i]}" convert "midres_${arr_files_JPG[$i]}" -resize "$LOW_RES_MODE" "lowres_${arr_files_JPG[$i]}" done fi echo -e " [OK]\n" echo -n 'Changing the original filenames to hires' for i in `ls -1 | grep -v lowres | grep -v midres`; do mv $i hires_$i; done && echo -e " [OK]" else echo -en "\nConverting phase [OMITTED]" fi if [ "$compress_status" = 'y' ] then echo -e "Starting compression phase \n" echo -n ' 1) compressing lowres files ' zip -q compressed_lowres.zip lowres* && echo ' [OK]' echo -n ' 2) compressing midres files ' zip -q compressed_midres.zip midres* && echo ' [OK]' echo -n ' 3) compressing hires files ' zip -q compressed_hires.zip hires* && echo -e " [OK]\n" else echo -e "\nCompressing phase [OMITTED]" fi if [ "$clean_status" = 'y' ] then echo -ne "\nStarting cleaning phase " mv ./*zip ../ && cd ../ && rm -rf ./temp && echo -e " [OK]\n" else echo -e "Cleaning phase [OMITTED]\n" fi if [ "$error_status" = '1' ] then echo -e "SUMMARY: An unknown error has occur during the program work - check the folder tree..\n" else echo -e "SUMMARY: There wasn't errors during the program work..\n" fi