Advertisement
Guest User

Untitled

a guest
Nov 28th, 2015
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.74 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ################################################################################
  4. # screenshots.sh
  5. # - ImageMagick must be installed (http://wiki.ubuntuusers.de/ImageMagick).
  6. # - Makes a gif image from screenshots (e.g. for ZDS).
  7. # - Number of ZDS will be calculated.
  8. # V1.1.0
  9. #
  10. # Changelog:
  11. # V1.0.0
  12. # - Initial version
  13. #
  14. # V1.1.0
  15. # - Bugfix ZDS number
  16. # - Input and output cleanup
  17. #
  18. #
  19. ################################################################################
  20.  
  21. # Init
  22. out_count=0
  23. screenshot_temp=screenshot_temp_
  24. firstzds=20070901
  25. delay_time=250  # 1/100 seconds
  26. gamma=1.35
  27.  
  28. # Number of images
  29. images_count=$(find *.png | wc -l)
  30.  
  31. # Calculating ZDS number
  32. tmp=$( date -d $firstzds +%s )
  33. zds=$(( (`date +%s` - $tmp) / 86400 / 7 ))
  34.  
  35.  
  36. ################################################################################
  37. # Script start
  38. echo ""
  39. echo ""
  40. echo "Screenshots to gif"
  41. echo "~~~~~~~~~~~~~~~~~~"
  42. echo ""
  43.  
  44. # Checking ImageMagick
  45. if which convert > /dev/null; then
  46.     echo "ImageMagick found"
  47. else
  48.     echo "ImageMagick not installed!"
  49.     echo ""
  50.     exit
  51. fi
  52.  
  53. # Checking number of images
  54. if [ $images_count == 0 ]; then
  55.     echo "No images found!"
  56.     echo ""
  57.     exit
  58.     else if [ $images_count == 1 ]; then
  59.         echo "1 image found, nothing to do!"
  60.         echo ""
  61.         exit
  62.     else
  63.         echo $images_count" images found"
  64.     fi
  65. fi
  66.  
  67. # Enter resolution
  68. while [ TRUE ]; do
  69.     echo ""
  70.     echo "1)  4:3 (800x600)"
  71.     echo "2) 16:9 (928x522)"
  72.     echo -n "Resolution: "
  73.     read Select
  74.     case $Select in
  75.         1)
  76.             Resolution=800
  77.             break  
  78.         ;;
  79.         2)
  80.             Resolution=928
  81.             break
  82.         ;;
  83.         # default: loop
  84.     esac
  85. done
  86.  
  87. # Enter output filename
  88. echo ""
  89. echo -n "File name (no extension, Enter = 'zds-"$zds"_screenshots.gif'): "
  90. read outputfile
  91.  
  92. if [ "$outputfile" = "" ]; then
  93.     outputfile="zds-"$zds"_screenshots.gif"
  94. else
  95.     outputfile=$outputfile".gif"
  96. fi
  97.  
  98. # Get start time
  99. starttime=$(date +%s)
  100.  
  101. # Creat temporary bmp files in 24 bit
  102. echo ""
  103. echo -n "Converting to 24 bit and resizing: "
  104. for i in *.png
  105.     do
  106.     let "out_count++"
  107.     #echo "Input: $i -> Output: $screenshot_temp$(printf '%04d' "$out_count").bmp" # debug
  108.     let "percentage = (out_count * 100) / $images_count"
  109.     printf "%3d%%" $percentage
  110.     nice -n 6 convert $i -resize "$Resolution"x -gamma $gamma -depth 24 $screenshot_temp$(printf '%04d' "$out_count").bmp
  111.     echo -ne '\b\b\b\b'
  112. done
  113. echo -ne '\b'
  114. echo ""
  115.  
  116. # Creat gif
  117. echo -n "Creating '$outputfile'..."
  118. nice -n 6 convert -type optimize -delay $delay_time -loop 0 $screenshot_temp*.bmp "$outputfile"
  119. echo "done"
  120.  
  121. # Delete bmp files
  122. echo -n "Cleaning temporary files..."
  123. rm $screenshot_temp*.bmp
  124. echo "done"
  125.  
  126. # End time
  127. timeend=$(date +%s)
  128. let "timediff = $timeend - $starttime"
  129. echo "Time: $timediff seconds"
  130. echo ""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement