crop.sh 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. # Crop one image into another, after first checking that the source
  3. # image has the expected size in pixels.
  4. #
  5. # This is used in the Puzzles icon build scripts to construct icons
  6. # which are zoomed in on a particular sub-area of the puzzle's
  7. # basic screenshot. This way I can define crop areas in pixels,
  8. # while not having to worry too much that if I adjust the source
  9. # puzzle so as to alter the layout the crop area might start
  10. # hitting the wrong bit of picture. Most layout changes I can
  11. # conveniently imagine will also alter the overall image size, so
  12. # this script will give a build error and alert me to the fact that
  13. # I need to fiddle with the icon makefile.
  14. identify="$1"
  15. convert="$2"
  16. infile="$3"
  17. outfile="$4"
  18. insize="$5"
  19. crop="$6"
  20. # Special case: if no input size or crop parameter was specified at
  21. # all, we just copy the input to the output file.
  22. if test -z "$insize"; then
  23. cp "$infile" "$outfile"
  24. exit 0
  25. fi
  26. # Check the input image size.
  27. realsize=$("$identify" -format %wx%h "$infile")
  28. if test "x$insize" != "x$realsize"; then
  29. echo "crop.sh: '$infile' has wrong initial size: $realsize != $insize" >&2
  30. exit 1
  31. fi
  32. # And crop.
  33. "$convert" -crop "$crop" "$infile" "$outfile"