Skip to content

Instantly share code, notes, and snippets.

@michelbrito
Created December 19, 2012 10:02
Show Gist options
  • Select an option

  • Save michelbrito/4335678 to your computer and use it in GitHub Desktop.

Select an option

Save michelbrito/4335678 to your computer and use it in GitHub Desktop.

Revisions

  1. michelbrito created this gist Dec 19, 2012.
    20 changes: 20 additions & 0 deletions retina2nonretina.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash
    # Downsamples all retina [email protected] images.

    echo "Downsampling retina images..."

    dir=$(pwd)
    find "$dir" -name "*@2x.png" | while read image; do

    outfile=$(dirname "$image")/$(basename "$image" @2x.png).png

    if [ "$image" -nt "$outfile" ]; then
    basename "$outfile"

    width=$(sips -g "pixelWidth" "$image" | awk 'FNR>1 {print $2}')
    height=$(sips -g "pixelHeight" "$image" | awk 'FNR>1 {print $2}')
    sips -z $(($height / 2)) $(($width / 2)) "$image" --out "$outfile"

    test "$outfile" -nt "$image" || exit 1
    fi
    done