WD Cloud Piwigo Thumbnail shell script
1. convert 유틸설치
1 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
#!/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