10
10

More than 5 years have passed since last update.

OSXでスクリーンキャプチャのシェルスクリプトRetina対応版

Posted at

OSXでスクリーンキャプチャをとるシェルスクリプトです。Retina対応版というのは具体的には、キャプチャした画像が72dpi以外なら72dpiになるようにリサイズする処理を入れています。

capture.sh
#!/bin/sh
f=${1:-~/Desktop/capture-`date '+%Y%m%d-%H%M%S'`.png}
/usr/sbin/screencapture -i $f 2>/dev/null
/usr/bin/sips -g dpiWidth -g dpiHeight -g pixelWidth -g pixelHeight $f |
/usr/bin/awk -v imagefile=$f '
$1=="dpiWidth:" {dpiWidth = $2}
$1=="dpiHeight:" {dpiHeight = $2}
$1=="pixelWidth:" {pixelWidth = $2}
$1=="pixelHeight:" {pixelHeight = $2}
END {
  if (dpiWidth != 72 || dpiHeight != 72) {
    w = int(pixelWidth * 72 / dpiWidth)
    h = int(pixelHeight * 72 / dpiHeight)
    cmd = sprintf("/usr/bin/sips %s -s dpiWidth 72 -s dpiHeight 72 -z %d %d >/dev/null 2>&1", imagefile, h, w)
    system(cmd)
  }
}
'

Ben Alman » Fixing "Retina" Image Scaling with Gyazo の記事と dotfiles/bin/resample-dpi at master · cowboy/dotfiles · GitHub のスクリプトを参考に作りました。ありがとうございます。

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10