Permalink
Browse files

Adding resample-dpi helper script for post-processing retina MacBook …

…Pro screengrabs.
  • Loading branch information...
1 parent b9a2a6a commit 1d26c50a2cfe86c4f71675b037ce2b6fbbdf188f @cowboy committed Jul 16, 2012
Showing with 38 additions and 0 deletions.
  1. +38 −0 bin/resample-dpi
View
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+if [[ ! "$1" || "$1" == "-h" || "$1" == "--help" ]]; then cat <<HELP
+Resample specified images to 72 DPI
+http://benalman.com/
+
+Usage: $(basename "$0") [img [img ...]]
+
+The new MacBook Pro retina display is amazing, but screengrabs taken on
+one using the screencapture utility aren't scaled to 72 DPI by default.
+This script scales those images to 72 DPI, making them viewable at a sane
+resolution in web browsers.
+
+Copyright (c) 2012 "Cowboy" Ben Alman
+Licensed under the MIT license.
+http://benalman.com/about/license/
+HELP
+[[ "$1" ]]; exit; fi
+
+while [[ "$1" ]]; do
+ file="$1"; shift
+
+ dpiWidth=$(sips "$file" -g dpiWidth | awk '/:/ {print $2}')
+ dpiHeight=$(sips "$file" -g dpiHeight | awk '/:/ {print $2}')
+ pixelWidth=$(sips "$file" -g pixelWidth | awk '/:/ {print $2}')
+ pixelHeight=$(sips "$file" -g pixelHeight | awk '/:/ {print $2}')
+
+ if [[ "$(echo "$dpiWidth - 72" | bc)" == "0" || "$(echo "$dpiHeight - 72" | bc)" == "0" ]]; then
+ echo "File $(basename "$file") already ${pixelWidth}x${pixelHeight} pixels @ 72 DPI."
+ continue
+ fi
+
+ w=$(echo "$pixelWidth * 72 / $dpiWidth" | bc)
+ h=$(echo "$pixelHeight * 72 / $dpiHeight" | bc)
+
+ echo "Resampling $(basename "$file") to ${w}x${h} pixels @ 72 DPI."
+ sips "$file" -s dpiWidth 72 -s dpiHeight 72 -z $h $w >/dev/null 2>&1
+done

0 comments on commit 1d26c50

Please sign in to comment.