-
-
Save mostlygeek/7131906 to your computer and use it in GitHub Desktop.
An easy (ha!) way to resize and png optimize screenshots in OSX. This is good for resampling and then optimizing retina screenshots when sending to people. It dumps things into Dropbox/public/Screenshots, and copies the public URL to the clipboard. Bind it to a hot key to to make it easy to use. Check out the output: https://dl.dropboxuserconten…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ******************************* | |
# Instructions on turning this into an OSX service: | |
# http://blog.lanceli.com/2012/08/downscale-screenshot-at-hight-resolution-on-retina-mackbook-pro.html | |
# ******************************* | |
# the path where screenshots to save | |
DROPBOX_ID= ENTER YOUR DROPBOX ID HERE | |
SS_PATH="/Users/$(whoami)/Dropbox/Public/Screenshots" | |
if [ ! -e $SS_PATH ] | |
then | |
mkdir -p $SS_PATH | |
fi | |
# if you want to save them to your desktop, SS_PATH should be "/Users/YOURNAME/Desktop" | |
# a variable of unix timestamp for screenshot file name | |
NOW=$(date +%s) | |
OUT=$(mktemp /tmp/XXXXX) | |
PNGQUANT='/Applications/ImageAlpha.app/Contents/Resources/pngquant' | |
# execute screen capture command, screenshot$NOW.png is the name of file | |
screencapture -t png -i $OUT | |
# check the DPI, if it is 2x res (144dpi), then reduce it... | |
DPI=$(sips -g dpiWidth $OUT | tail -1 | awk '{print $2/1}') | |
echo $DPI | |
if [ $DPI -eq 144 ] | |
then | |
WIDTH=$(sips -g pixelWidth $OUT | awk '/pixelWidth/ {print $2/2}') | |
TMP=$(mktemp /tmp/XXXXX) | |
sips --resampleWidth $WIDTH $OUT --out $TMP | |
rm $OUT | |
mv $TMP $OUT | |
fi | |
if [ -e $PNGQUANT ] | |
then | |
TMP=$(mktemp /tmp/XXXXX) | |
cat $OUT | $PNGQUANT - > $TMP | |
rm $OUT | |
mv $TMP $SS_PATH/$(basename $OUT).png | |
else | |
mv $OUT $SS_PATH/$(basename $OUT).png | |
fi | |
# copy that | |
echo "https://dl.dropboxusercontent.com/u/$DROPBOX_ID/Screenshots/$(basename $OUT).png" | pbcopy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment