Advertisement
melior

HairSample2Overlay.sh

Jun 6th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.59 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Check number of inputs
  4. if [ $# -lt 2 -o $# -gt 3 ]; then
  5.     echo "Needs two or three input arguments"
  6.     exit 0;
  7. fi
  8.  
  9. # Split hair image
  10. convert "$1" -crop 40x40 +repage zzztmp.png
  11.  
  12. # Get row to use
  13. n=`ls -1 zzztmp*.png | wc -l`
  14. nrows=`echo "$n/3" | bc`
  15. if [ $# -eq 3 ]; then
  16.     if [ $3 -gt $nrows ]; then
  17.         echo "Chosen row does not exist, selecting row 1"
  18.         row="1"
  19.     else
  20.         row="$3"
  21.     fi
  22. else
  23.     row="-1"
  24. fi
  25.  
  26.  
  27. # this function takes:
  28. # (1) the image number of the front-facing hair in the row you want to use
  29. # (2) the output image name
  30. disthair () {
  31.  
  32.     # Distribute hair from the chosen row
  33.     front=`echo "("$1"-1)*3" | bc`
  34.     back=`echo "$front+1" | bc`
  35.     right=`echo "$back+1" | bc`
  36.     left="r$right"
  37.  
  38.     # Make a left-facing hair image
  39.     convert zzztmp-$right.png -flop zzztmp-$left.png
  40.  
  41.     # Create blank convas
  42.     convert -size 576x256 canvas:none "$2"
  43.  
  44.     # Now place the hair on the blank canvas where needed.
  45.     # Rear-facing
  46.     composite -geometry +12+8 zzztmp-$back.png "$2" "$2"
  47.     composite -geometry +76+8 zzztmp-$back.png "$2" "$2"
  48.     composite -geometry +140+8 zzztmp-$back.png "$2" "$2"
  49.     composite -geometry +204+9 zzztmp-$back.png "$2" "$2"
  50.     composite -geometry +268+8 zzztmp-$back.png "$2" "$2"
  51.     composite -geometry +332+8 zzztmp-$back.png "$2" "$2"
  52.     composite -geometry +396+8 zzztmp-$back.png "$2" "$2"
  53.     composite -geometry +460+9 zzztmp-$back.png "$2" "$2"
  54.     composite -geometry +524+8 zzztmp-$back.png "$2" "$2"
  55.  
  56.     # Left-facing
  57.     composite -geometry +14+72 zzztmp-$left.png "$2" "$2"
  58.     composite -geometry +78+73 zzztmp-$left.png "$2" "$2"
  59.     composite -geometry +142+73 zzztmp-$left.png "$2" "$2"
  60.     composite -geometry +206+72 zzztmp-$left.png "$2" "$2"
  61.     composite -geometry +270+72 zzztmp-$left.png "$2" "$2"
  62.     composite -geometry +334+73 zzztmp-$left.png "$2" "$2"
  63.     composite -geometry +398+73 zzztmp-$left.png "$2" "$2"
  64.     composite -geometry +462+72 zzztmp-$left.png "$2" "$2"
  65.     composite -geometry +526+72 zzztmp-$left.png "$2" "$2"
  66.  
  67.     # Front-facing
  68.     composite -geometry +12+135 zzztmp-$front.png "$2" "$2"
  69.     composite -geometry +76+135 zzztmp-$front.png "$2" "$2"
  70.     composite -geometry +140+135 zzztmp-$front.png "$2" "$2"
  71.     composite -geometry +204+136 zzztmp-$front.png "$2" "$2"
  72.     composite -geometry +268+135 zzztmp-$front.png "$2" "$2"
  73.     composite -geometry +332+135 zzztmp-$front.png "$2" "$2"
  74.     composite -geometry +396+135 zzztmp-$front.png "$2" "$2"
  75.     composite -geometry +460+136 zzztmp-$front.png "$2" "$2"
  76.     composite -geometry +524+135 zzztmp-$front.png "$2" "$2"
  77.  
  78.     # Right-facing
  79.     composite -geometry +10+200 zzztmp-$right.png "$2" "$2"
  80.     composite -geometry +74+201 zzztmp-$right.png "$2" "$2"
  81.     composite -geometry +138+201 zzztmp-$right.png "$2" "$2"
  82.     composite -geometry +202+200 zzztmp-$right.png "$2" "$2"
  83.     composite -geometry +266+200 zzztmp-$right.png "$2" "$2"
  84.     composite -geometry +330+201 zzztmp-$right.png "$2" "$2"
  85.     composite -geometry +394+201 zzztmp-$right.png "$2" "$2"
  86.     composite -geometry +458+200 zzztmp-$right.png "$2" "$2"
  87.     composite -geometry +522+200 zzztmp-$right.png "$2" "$2"
  88.  
  89. }
  90.  
  91.  
  92. # Finally, run disthair on the selected row (or all rows)
  93. if [ "$row" -ne "-1" ]; then
  94.     disthair "$row" "$2"
  95.     echo "Converted row $row into $2"
  96. else
  97.     for (( k=1; k<=$nrows; k++ ))
  98.     do
  99.         fn=${2%.*}
  100.         ex=${2##*.}
  101.         outname="$fn-$k.$ex"
  102.         disthair "$k" "$outname"
  103.         echo "Converted row $k into $outname"
  104.     done
  105. fi
  106.  
  107. rm zzztmp-*.png
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement