Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.71 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. file=$(sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' <<< "$QUERY_STRING" | xargs echo -e )
  4. file=${file##*/}
  5. file=${file%%;*}
  6.  
  7. if [ -e "$file" ]; then
  8.     sum=$(md5sum "$file" | sed -e 's/^\([0-9a-fA-F]*\)\s.*$/\1/')
  9.     sum="/tmp/thumbs/$sum"
  10.  
  11.     mkdir -p /tmp/thumbs
  12.     if ! [ -e "$sum" ]; then
  13.         convert "$file" -auto-orient -thumbnail 250x90 -unsharp 0x.5 "gif:$sum"
  14.     fi
  15.  
  16.     export TZ=UTC0
  17.     t=$(stat --printf="%Y" "$sum")
  18.     mod=$(awk "BEGIN{print strftime(\"%a, %d %b %Y %H:%M:%S %Z\", $t)}")
  19.  
  20.     cat <<-EOF
  21.         Content-Type: image/gif
  22.         Last-Modified: $mod
  23.  
  24.     EOF
  25.  
  26.     cat "$sum"
  27. else
  28.     cat <<-EOF
  29.         Status: 400 Bad Image Request
  30.  
  31.     EOF
  32. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement