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

kill_image.sh

By: a guest on Aug 12th, 2012  |  syntax: Bash  |  size: 1.09 KB  |  views: 15  |  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. # usage: kill_image ITERATIONS IMAGE
  4. # converts IMAGE to a mpeg and back to the original format ITERATIONS times,
  5. # adding a numeric suffix to each step
  6. # coded by e36freak
  7. # MIT License
  8. # assign options to vars after checking validity
  9. if (($# < 2)); then
  10.   printf '%s\n' 'not enough options' >&2
  11.   exit 1
  12. fi
  13.  
  14. if [[ -z $1 || $1 = *[!0-9]* ]]; then
  15.   printf 'invalid number for ITERATIONS: %s\n' "$1" >&2
  16.   exit 1
  17. fi
  18.  
  19. times=$1
  20.  
  21. if [[ ! -f $2 || ! -r $2 ]]; then
  22.   printf '%s: permission denied\n' >&2
  23.   exit 1
  24. fi
  25.  
  26. image=$2
  27.  
  28. # get prefix and extension
  29. pref=${image%.*}
  30. ext=${image##*.}
  31.  
  32. # determine how many zeroes to pad
  33. len=${#times}
  34.  
  35. # store previously generated image
  36. prev=$image
  37.  
  38. # loop ITERATIONS times
  39. for ((i=1; i<=times; i++)); do
  40.   # 0-pad suffix
  41.   printf -v suff '%0*d' "$len" "$i"
  42.  
  43.   # convert from original format to mpeg
  44.   convert "$prev" "$pref.mpeg" &&
  45.   # convert back to original extension, adding suffix
  46.   convert "$pref.mpeg" "$pref$suff.$ext" || continue
  47.   # remove mpeg file, not needed
  48.   rm "$pref.mpeg"
  49.  
  50.   prev=$pref$suff.$ext
  51. done
clone this paste RAW Paste Data