Skip to content

Instantly share code, notes, and snippets.

@totakke
Last active April 26, 2016 07:10
Show Gist options
  • Save totakke/17a0a40c413f88b76c05 to your computer and use it in GitHub Desktop.
Save totakke/17a0a40c413f88b76c05 to your computer and use it in GitHub Desktop.
A cropping script for iOS screenshots
#!/bin/sh
#
# A cropping script for iOS screenshots
#
# This shell script crops an iOS screenshot without the status bar. It
# automatically detects a display size of a screenshot, and cuts its status bar
# using ImageMagick. It currently supports portrait screenshots of 3.5 and 4
# inch iPhone.
#
# Usage:
# $ ./status-bar-crop.sh foo.png
#
# Check arguments
if [ $# -lt 1 ]; then
echo "Invalid arguments" 1>&2
echo "Usage: $0 foo.png" 1>&2
exit 1
fi
# Check ImageMagick
if [ ! `which mogrify` ]; then
echo "ImageMagick is not found" 1>&2
exit 1
fi
# Cropping
for IMG in `ls $*`; do
WIDTH=`identify -format '%w' -quiet $IMG`
HEIGHT=`identify -format '%h' -quiet $IMG`
if [ $WIDTH -eq 640 -a $HEIGHT -eq 960 ]; then
# 3.5 inch
mogrify -crop 640x920+0+40 -quiet $IMG
echo "Cropped $IMG"
elif [ $WIDTH -eq 640 -a $HEIGHT -eq 1136 ]; then
# 4 inch
mogrify -crop 640x1096+0+40 -quiet $IMG
echo "Cropped $IMG"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment