Skip to content

Instantly share code, notes, and snippets.

@furandon-pig
Created August 30, 2014 17:45
Show Gist options
  • Save furandon-pig/d3b0bde3783a27c5f715 to your computer and use it in GitHub Desktop.
Save furandon-pig/d3b0bde3783a27c5f715 to your computer and use it in GitHub Desktop.
MagicPoingで生成したスライド画像をリサイズするスクリプトです。
#!/bin/sh
# MagicPoingで生成したスライド画像をリサイズするスクリプトです。
# 使用例:
# $ mkdir html
# $ mgp -g 958x766 -D html -E png slide.mgp
# $ cd html
# $ ~/bin/convert_mgp_slide_size.sh
# 処理の進捗状況を確認しやすくするため、はじめに処理対象となる
# 画像ファイル数をカウントする。
_sum=0
for i in `ls *.png | grep -v idx`
do
_sum=$((_sum+1))
done
# 画像をリサイズする。
_count=0
for i in `ls *.png | grep -v idx`
do
_count=$((_count+1))
convert -geometry 50% $i $i.tmp
if [ $? -eq 0 ]; then
mv $i.tmp $i
echo "(${_count}/${_sum}) resized ${i}"
else
echo "(${_count}/${_sum}) ERR: failed resize ${i}"
fi
done
# htmlファイル中のIMGタグには、元画像のwidth,heightが設定されて
# いるため、それらの値をリサイズ後の値で置き換える。
#
# リサイズ後のwidth,heightはfileコマンドの結果から取得する。
# $ file mgp00001.png
# mgp00001.png: PNG image, 479 x 383, 8-bit/color RGB, non-interlaced
# $4が width, $6がheight
_img=`ls *.png | grep -v idx | head -n1`
_img_info=`file $_img`
_width=`echo ${_img_info} | awk '{ print $4}'`
_height=`echo ${_img_info} | awk '{ print $6}'`
for i in `/bin/ls mgp*.html`
do
cat $i | sed \
-e "s/WIDTH=.* HEIGHT/WIDTH= "${_width}" HEIGHT/" \
-e "s/HEIGHT=.* ALT/HEIGHT= "${_height}" ALT/" \
-e "s/WIDTH= /WIDTH=/" \
-e "s/HEIGHT= /HEIGHT=/" \
| iconv -f cp932 -t utf-8 \
> $i.tmp
mv $i.tmp $i
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment