textimage.sh 988 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/bin/sh
  2. #####################################################
  3. # textimage.sh
  4. #
  5. # This sample/default shell script generates a JPEG
  6. # image file containing a text string, preceded by
  7. # HTTP headers.
  8. #
  9. # It uses the "convert" command from ImageMagick:
  10. # http://www.Imagemagick.org/
  11. #
  12. #####################################################
  13. # string to generate
  14. string=$1
  15. # prefix to use for temporary file names
  16. prefix=$2
  17. # name for temporary image file
  18. imgfile=$prefix.jpeg
  19. # for debuging
  20. #echo textimage.sh: string=$string imgfile=$imgfile 1>&2
  21. #echo PATH=$PATH 1>&2
  22. # generate the image file
  23. convert \
  24. -geometry 190x30! -pointsize 24 -font helvetica \
  25. -draw "text 0,24 $string" xc:white $imgfile
  26. retcode=$?
  27. # nothing to STDOUT on failure
  28. if [ $retcode != 0 ]; then
  29. logger -t textimage.sh "convert" command failed - see HTTP server log
  30. exit $retcode
  31. fi
  32. # output HTTP header and file
  33. echo "Content-Type: image/jpeg"
  34. echo
  35. cat $imgfile
  36. # remove temporary file
  37. rm $imgfile