Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Jan 17th, 2013  |  syntax: Bash  |  size: 3.01 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2. #
  3. #
  4. #
  5. # find /media/sf_test/meklee/ -type f -iname "*.jpg" -exec /root/imagick_script.sh "{}" \;
  6. #
  7. # depends on jhead and imagemagick
  8. # if call find from another file, then is possible to count all pictures, place it on file and in imagick_script.sh
  9. # decrase that amount by 1.
  10. #
  11. # in script some directory names is in Latvian :)
  12. #
  13.  
  14. backgroundimage=$1
  15. bgp=/media/sf_test/
  16.  
  17.  
  18. if [ -f "${bgp}stop" ]
  19. then
  20.     echo -ne "*"
  21.     exit 0
  22. fi
  23.  
  24. if [ ! -d "${bgp}2019" ]
  25. then
  26.     mkdir -p "${bgp}2019"
  27. fi
  28.  
  29. # "%[fx:w] %[fx:h] %[exif:DateTime]" (use this if images has no exif data)
  30. #dim=`identify -format "%[fx:.15*w] %[fx:.15*h] %[exif:orientation] %[exif:DateTime]" "$backgroundimage"`
  31.  
  32. # be careful with auto-orient
  33. # see this: http://www.imagemagick.org/script/command-line-options.php?#auto-orient
  34. #orient=`echo $dim | awk '{print $3}'`
  35. #if [ "$orient" != "1" ]
  36. #then
  37. #orient image (rewrite original)
  38. #    convert -auto-orient "$1" "$1"
  39. #re-read image data
  40. #    dim=`identify -format "%[fx:.15*w] %[fx:.15*h] %[exif:orientation] %[exif:DateTime]" "$backgroundimage"`
  41. #fi
  42.  
  43.  
  44. # jhead is much faster...
  45.  
  46.  
  47. #ww=`echo $dim | awk '{print $1}'`
  48. #hh=`echo $dim | awk '{print $2}'`
  49. #ww=`printf "%.0f\n" "${ww}"`
  50. #hh=`printf "%.0f\n" "${hh}"`
  51. ww=`jhead "$1" | grep 'Resolution' | awk '{print $3}'`
  52. hh=`jhead "$1" | grep 'Resolution' | awk '{print $5}'`
  53. ww=`echo "$ww * .15" | bc -l  | xargs printf "%1.0f"`
  54. hh=`echo "$hh * .15" | bc -l  | xargs printf "%1.0f"`
  55.  
  56.  
  57. if [ "$hh" -gt "$ww" ]
  58. then
  59.     let ww=$ww*2
  60. fi
  61.  
  62. #year=`echo $dim | awk '{print substr($4,1,4)}'`
  63. # works only if exif is avaiable..
  64. year=`jhead "$1" | grep 'File date' | awk '{print substr($4,1,4)}'`
  65.  
  66. # i have images takin in range from 2004 to 2012, so if some exim data is removed, use year 2019..
  67. case "$year" in
  68. '2004')
  69.     #
  70. ;;
  71. '2005')
  72.     #
  73. ;;
  74. '2006')
  75.     #
  76. ;;
  77. '2007')
  78.     #
  79. ;;
  80. '2008')
  81.     #
  82. ;;
  83. '2009')
  84.     #
  85. ;;
  86. '2010')
  87.     #
  88. ;;
  89. '2011')
  90.     #
  91. ;;
  92. '2012')
  93.     #
  94. ;;
  95. *)
  96.     year=2019
  97.     mv "$1" "${bgp}2019"
  98.     echo -ne "!"
  99.     exit 0
  100. ;;
  101. esac
  102.  
  103.  
  104.  
  105. if [ ! -f ${bgp}${year}.png ];
  106. then
  107.     convert -gravity southeast -size 300x130 xc:transparent -font Courier-bold -pointsize 125 -fill red -draw "text 0,0 '${year}'" ${bgp}output.png
  108.     composite  ${bgp}output.png ${bgp}fons.png ${bgp}${year}.png
  109.     #echo "${year}.png not found, create one ..";
  110. fi
  111.  
  112. Watermark=${bgp}${year}.png
  113.  
  114.  
  115. Fname="${backgroundimage##*/}"
  116. Fdir="${backgroundimage:0:${#backgroundimage} - ${#Fname}}"
  117. #echo "${Fdir}new_$Fname"
  118. #echo "${ww}x$hh $1"
  119. if [ ! -d "/media/sf_test/resize/$year/" ]
  120. then
  121.     mkdir "/media/sf_test/resize/$year/"
  122. fi
  123.  
  124. if [ ! -d "/media/sf_test/apstradatie/$year/" ]
  125. then
  126.     mkdir "/media/sf_test/apstradatie/$year/"
  127. fi
  128.  
  129. if [ ! -f "/media/sf_test/resize/$year/$Fname" ]
  130. then
  131.     composite -gravity southeast \( $Watermark -resize ${ww}x${hh} \) "$backgroundimage" "/media/sf_test/resize/$year/$Fname"
  132. fi
  133. mv "$1" "/media/sf_test/apstradatie/$year"
  134. #"${Fdir}neew_$Fname"
  135.  
  136. echo -ne "."