Downscale a iMac 5K screenshot to 50% using commandline

  1. Open the Screenshot in Preview
  2. Select “Adjust Size…” from the Tools menu
  3. Change the Width and Height to 50 percent of the original
  4. Change the Resolution to 72 pixels/inch

I wish to do this on CLI with a generic command (percent, not actual width and height).

GUI instructions with Preview


Solution 1:

You can do it with imagemagick by typing the following:

convert image.png -resize 50% -density 72 image.png

In order to execute the previous command you need imagemagick installed on your computer. You can easy do it via homebrew:

brew install imagemagick

And, if you haven't homebrew, you can install with this:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Solution 2:

Take a look at the 'sips' command:

man sips

It is much simpler than GUI-scripting Preview and it's part of OSX. So you don't have to install anything. Example:

full_w=$(/usr/bin/sips -g pixelWidth image.jpg | /usr/bin/grep -Eo "[[:digit:]]+")
full_h=$(/usr/bin/sips -g pixelHeight image.jpg | /usr/bin/grep -Eo "[[:digit:]]+")
half_w=$(/bin/expr full_w / 2)
half_h=$(/bin/expr full_h / 2)
sips -z half_h half_w image.jpg