WD Cloud Piwigo Thumbnail shell script
1. convert 유틸설치
apt-get install imagemagick
2.셀스크립트 작성 및 사용방법
아래의 내용으로 xxx.sh 생성후 권한 부여 chmod 777 xxx.sh
실행방법 : xxx.sh 인자 [ 인자는 startDataDir 디렉토리의 하위에 하위 폴더가 존재할시 사용하면 됨.]
예를 들자면
/DataVolume/www/pw/galleries/2012 ,
/DataVolume/www/pw/galleries/2012 /01,
/DataVolume/www/pw/galleries/2012 /02,
/DataVolume/www/pw/galleries/2011
/DataVolume/www/pw/galleries/2011/01
/DataVolume/www/pw/galleries/2011/02
위와 같은구조일 경우 /DataVolume/www/pw/galleries/2012 밑의 01, 02 …. 에 해당하는 폴더를 스캔하여 쎔네일
생성할려면
xxx.sh 2012 로 실행하면 하위 폴더포함하여 쎔네일 생성됨.
3.xxx.sh script
#!/bin/sh LANG=ko_KR.UTF-8 startGalDir='/DataVolume/www/pw/_data/i/galleries' startDataDir='/DataVolume/www/pw/galleries' userGroup='www-data:www-data' #DEBUG_MODE=echo arg=$1 function recursDir { echo "Dir-1 : $startDataDir/$arg" echo 'arg : $arg' cd $startDataDir/$arg pwd = $(pwd) echo $pwd local subDirs=$(find * -type d -prune) for subDire in $subDirs do echo "step #1 : $subDir" done for subDir in $subDirs; do local tree=$1 local photos='' local moveMe=0 local moveTh=0 cd $startDataDir/$arg/$subDir echo "Dir-2 : $startDataDir/$arg/$subDir" #----------------------------- # skip dir... #----------------------------- if [ $subDir = "backup" ]; then echo "$subDir is backup folder : skip ---------------" continue fi #----------------------------- # check dir... #----------------------------- if [ ! -d "$startGalDir/$arg$subDir" ]; then ${DEBUG_MODE} mkdir -p "$startGalDir/$arg/$subDir" echo "Create folder \"$startGalDir/$arg/$subDir\"" fi #----------------------------- # check done. #---------------------------- if [ -f "$startGalDir/$arg$subDir/thumb_done" ]; then echo skip this folder... #recursDir /$arg/$subDir"/" continue fi #120 x 120 sq #144 x 144 th #792 x 594 me ${DEBUG_MODE} [ ! -f "$startGalDir/$arg/$subDir/index.htm" ] && echo 'Not allowed!' > "$startGalDir/$arg/$subDir/index.htm" photos=$(find * -maxdepth 0 -type f -name '*.jpg' -o -name '*.JPG') for resize_target in $photos; do h=`identify -format "%h" $resize_target` w=`identify -format "%w" $resize_target` me="${resize_target%.jpg}-me.jpg" th="${resize_target%.jpg}-th.jpg" sq="${resize_target%.jpg}-sq.jpg" echo -ne "." # echo convert file $PWD/$resize_target [w:$w h:$h] if [ ! -f $startGalDir/$arg/$subDir/$th ]; then # echo create th file echo -ne "." ${DEBUG_MODE} convert -resize 144x144 -auto-orient $resize_target $th ${DEBUG_MODE} mv $th $startGalDir/$arg/$subDir fi if [ ! -f $startGalDir/$arg/$subDir/$sq ]; then # echo create sq file echo -ne "." if [ $w -ge $h ]; then ${DEBUG_MODE} convert -resize x120 -crop 120x120+0+0 $resize_target $sq else ${DEBUG_MODE} convert -resize 120x -crop 120x120+0+0 $resize_target $sq fi # convert -resize 120x120 -auto-orient $resize_target $sq ${DEBUG_MODE} mv $sq $startGalDir/$arg/$subDir fi if [ ! -f $startGalDir/$arg/$subDir/$me ]; then # echo create me file echo -ne "." ${DEBUG_MODE} convert -resize 792x -crop 792x594+0+0 $resize_target $me ${DEBUG_MODE} convert -auto-orient $me $me if [ $w -ge $h ]; then ${DEBUG_MODE} mv $me $startGalDir/$arg/$subDir else ${DEBUG_MODE} mv $me $startGalDir/$arg/$subDir fi fi done # ------------------------- # done.. #-------------------------- touch "$startGalDir/$arg/$subDir/thumb_done" echo "Into Dir /$arg/$subDir" #recursDir /$arg/$subDir"/" done } cd $startDir recursDir #chown -R $userGroup "$startDataDir" chmod -R u+rw,g+rw "$startDataDir"
출처 : http://xenostudy.tistory.com/445