Skip to content

Instantly share code, notes, and snippets.

@nsantorello
Created February 21, 2012 21:59
Show Gist options
  • Save nsantorello/1879276 to your computer and use it in GitHub Desktop.
Save nsantorello/1879276 to your computer and use it in GitHub Desktop.
For iPhone devs: Create a halved version of this file, and rename the full-size version to @2x.
#!/bin/bash
FILE=$1
BASE=${FILE%.*}
EXT=${FILE##*.}
cp "$FILE" "${BASE}@2x.${EXT}"
WIDTH_RAW=`sips -g pixelWidth "$FILE" | sed -n 2p`
WIDTH=${WIDTH_RAW##*:}
HEIGHT_RAW=`sips -g pixelHeight "$FILE" | sed -n 2p`
HEIGHT=${HEIGHT_RAW##*:}
HALF_WIDTH=`ruby -e "puts $WIDTH/2"`
HALF_HEIGHT=`ruby -e "puts $HEIGHT/2"`
sips -z $HALF_HEIGHT $HALF_WIDTH "$FILE"
# Only works on Macs since it relies on sips
#
# Run like:
# ./convert.sh myimage.jpg
# Or to convert all .jpg's in a directory:
# ls -1 | grep .jpg | xargs -L 1 -J % ./convert.sh "%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment