Skip to content

Instantly share code, notes, and snippets.

@raphaeltraviss
Created June 28, 2023 16:00
Show Gist options
  • Save raphaeltraviss/1d98bec91b50182b2c688f33c5d1f93d to your computer and use it in GitHub Desktop.
Save raphaeltraviss/1d98bec91b50182b2c688f33c5d1f93d to your computer and use it in GitHub Desktop.
macOS command to resize a hi-res image in the pasteboard to a normal size image, for pasting into applications that don't handle HPDI
#!/bin/bash
# Usage:
# copy image to pasteboard via CMD-C
# then call pbresize on command line
# or call with a custom scale e.g. pbresize 0.7
SCALE_FACTOR=${1:-0.5}
pngpaste /tmp/ss.png
IMG_WIDTH=$(sips -g pixelWidth /tmp/ss.png | cut -s -d ':' -f 2 | cut -c 2-)
SCALED_WIDTH=$(echo "$IMG_WIDTH * $SCALE_FACTOR" | bc)
sips -Z $SCALED_WIDTH /tmp/ss.png
impbcopy /tmp/ss.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment