LoginSignup
1
0

More than 5 years have passed since last update.

Macで画面の指定範囲のGIFアニメーションを生成する

Last updated at Posted at 2018-08-10

screencaptureコマンドとImageMagickを利用して、画面の指定範囲のGIFアニメーションを生成するスクリプトです。

準備

  • ImageMagickをインストール
$ brew install imagemagick

スクリプト

#!/bin/bash

CAP_FRAME_NUM=10
CAP_INTERVAL_SEC=1
CAP_POS_X=0
CAP_POS_Y=0
CAP_WIDTH=200
CAP_HEIGHT=200

GIF_FRAME_INTERVAL_MSEC=100
GIF_WIDTH=$CAP_WIDTH
GIF_HEIGHT=$CAP_HEIGHT

# `screencapture`コマンドで指定範囲の画面キャプチャを指定秒間隔で生成
for i in `seq -w 1 ${CAP_FRAME_NUM}`; do
    screencapture -R ${CAP_POS_X},${CAP_POS_Y},${CAP_WIDTH},${CAP_HEIGHT} -m frame_${i}.png
    sleep ${CAP_INTERVAL_SEC}
done

# 画面キャプチャ画像群をImageMagickでGIFアニメーションに変換
convert -delay ${GIF_FRAME_INTERVAL_MSEC} -loop 0 frame_*.png -resize ${GIF_WIDTH}x${GIF_HEIGHT} animation.gif

GIFの例

animation.gif

1
0
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
1
0