Created
December 10, 2013 22:20
-
-
Save geta6/7901350 to your computer and use it in GitHub Desktop.
並列化4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/zsh | |
START=$SECONDS | |
function terminate () { | |
echo 'Usage: endnanonna [target string] [output]' | |
exit 1 | |
} | |
[[ -z $1 ]] && echo 'target string blank.' && terminate | |
[[ ${#1} -ne 7 ]] && echo 'string length should be 7.' && terminate | |
[[ -z $2 ]] && echo 'no output.' && terminate | |
FONT='rounded-x-mplus-1p-black.ttf' | |
SRC="$1" | |
DST="$2" | |
CPU=4 | |
STRETCH=(6 6 15 24 24 60 80 90 100 110 120 124 134 136 137 138 139 140) | |
STRSIZE=(80 64 78 64 64 64 78) | |
GEOSIZE=(+80+5 +65+30 +115+15 +187+25 +240+25 +287+5 +335+0) | |
COLOURS=('#dd188b' '#dd188b' '#f57315' '#5ac02e' '#5ac02e' '#12a7c5' '#12a7c5') | |
ROTATES=('-10' '-10' '-10' '-10' '-10' '-10' 10) | |
FTMP=`mktemp -d` | |
FTMPORG="$FTMP/test.gif" | |
# generate | |
for i in {1..${#SRC}}; do | |
FTMPDST=$FTMP/$i.gif | |
convert -define gif:size=640x360 -background none -font $FONT -pointsize $STRSIZE[i] -fill $COLOURS[i] -stroke $COLOURS[i] -strokewidth 2 label:$SRC[i] -rotate $ROTATES[i] $FTMPDST | |
if [ $i -eq 1 -o $i -eq 6 -o $i -eq 7 ]; then | |
HEI=`echo $(( $STRSIZE[i] * 2.7 )) | cut -d'.' -f1` | |
convert -define gif:size=640x360 -geometry "x$HEI!" $FTMPDST $FTMPDST | |
fi | |
done | |
# append | |
SPLICE=0 | |
for s in $STRSIZE; do | |
f=`echo $(( s / 10 )) | cut -d'.' -f1` | |
SPLICE=$(( $SPLICE + $s - $f )) | |
done | |
convert -define gif:size=640x360 -background none -gravity east -splice ${SPLICE}x $FTMP/1.gif $FTMPORG | |
for i in {2..${#SRC}}; do | |
convert -define gif:size=640x360 $FTMPORG $FTMP/$i.gif -gravity west -geometry $GEOSIZE[i] -composite $FTMPORG | |
done | |
#convert -crop '100%x65-50+25' $FTMPORG $FTMPORG | |
#rm -r $FTMP | |
i=1 | |
c=0 | |
TMP=`mktemp -d` | |
for f in ./img/*.gif; do | |
NUM=$(( `echo $f | cut -d'/' -f3 | cut -d'.' -f1` )) | |
if [ $NUM -gt 106 ]; then | |
FTMPSRC=$FTMPORG | |
if [ $NUM -lt 124 ]; then | |
HEI=$STRETCH[i] | |
FTMPDST=$FTMP/${i}_sh.gif | |
convert -define gif:size=640x360 -geometry "x$HEI!" $FTMPSRC $FTMPDST | |
FTMPSRC=$FTMPDST | |
i=$(( i + 1 )) | |
fi | |
GEO=$(( 74 - $HEI / 2 )) | |
convert -define gif:size=640x360 $f $FTMPSRC -gravity center -geometry "+60+$GEO" -composite $TMP/`printf '%04d' ${NUM}`.gif & | |
c=$(( c + 1 )) | |
if [ $c -ge $CPU ]; then | |
c=0 | |
wait | |
fi | |
else | |
cp $f $TMP/`printf '%04d' ${NUM}`.gif | |
fi | |
done | |
wait | |
GIF=`gifsicle -O3 --delay 7 $TMP/*.gif > $DST` > /dev/null 2>&1 | |
rm -rf $TMP | |
rm -rf $FTMP | |
echo $(( $SECONDS - $START ))s | |
exit 0 | |
#TMP=`mktemp -d` | |
#DST="$2" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment