-
Notifications
You must be signed in to change notification settings - Fork 494
/
resample-dpi
executable file
·38 lines (29 loc) · 1.29 KB
/
resample-dpi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env 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