eps形式のアイコンをimgタグのsrcで使用したら表示できなかったので、eps形式をpng形式のファイルに変換したときのメモ。

gsコマンドを使用した。macの場合、brewでインストール。色々な依存ライブラリがインストールされて、結構時間がかかった。

$ brew install gs
Warning: It appears you have MacPorts or Fink installed.
Software installed with other package managers causes known problems for
Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again.
==> Installing dependencies for ghostscript: jpeg, libtiff, jbig2dec, little-cms2, libpng
==> Installing ghostscript dependency: jpeg
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/jpeg-8d.mavericks.bottle.2.tar.
######################################################################## 100.0%
==> Pouring jpeg-8d.mavericks.bottle.2.tar.gz
🍺  /usr/local/Cellar/jpeg/8d: 18 files, 780K
==> Installing ghostscript dependency: libtiff
==> Downloading ftp://ftp.remotesensing.org/pub/libtiff/tiff-4.0.3.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/libtiff/4.0.3 --without-x --disable-lzma --with-jpeg-incl
==> make install
🍺  /usr/local/Cellar/libtiff/4.0.3: 254 files, 3.8M, built in 26 seconds
==> Installing ghostscript dependency: jbig2dec
==> Downloading http://downloads.sourceforge.net/project/jbig2dec/jbig2dec/0.11/jbig2dec-0.11.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/jbig2dec/0.11
==> make install
🍺  /usr/local/Cellar/jbig2dec/0.11: 10 files, 268K, built in 9 seconds
==> Installing ghostscript dependency: little-cms2
==> Downloading http://downloads.sourceforge.net/project/lcms/lcms/2.5/lcms2-2.5.tar.gz
######################################################################## 100.0%
tar: copyfile unpack (lcms2-2.5/Projects/mac/LittleCMS/.DS_Store) failed: File exists
tar: copyfile unpack (lcms2-2.5/Projects/mac/.DS_Store) failed: File exists
==> ./configure --prefix=/usr/local/Cellar/little-cms2/2.5
==> make install
🍺  /usr/local/Cellar/little-cms2/2.5: 16 files, 1.0M, built in 55 seconds
==> Installing ghostscript dependency: libpng
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/libpng-1.5.17.mavericks.bottle.
######################################################################## 100.0%
==> Pouring libpng-1.5.17.mavericks.bottle.1.tar.gz
🍺  /usr/local/Cellar/libpng/1.5.17: 15 files, 1.0M
==> Installing ghostscript
==> Downloading http://downloads.ghostscript.com/public/ghostscript-9.07.tar.gz
######################################################################## 100.0%
tar: copyfile unpack (ghostscript-9.07/lcms2/Projects/mac/.DS_Store) failed: File exists
==> Patching
patching file base/unix-dll.mak
==> ./configure --prefix=/usr/local/Cellar/ghostscript/9.07 --disable-cups --disable-compile-inits -
==> make install
==> make install-so
==> Downloading http://downloads.sourceforge.net/project/gs-fonts/gs-fonts/8.11%20%28base%2035%2C%20
######################################################################## 100.0%
🍺  /usr/local/Cellar/ghostscript/9.07: 707 files, 49M, built in 10.0 minutes

次に、こちらのサイトを参考にしてスクリプト作成

$ cat eps_to_png
#!/bin/bash -f

INFILE=${1?}
OUTFILE=${INFILE//eps/png}

GS="gs -dBATCH -dNOPAUSE -dEPSCrop -r600 -sDEVICE=png16m -sOutputFile=${OUTFILE}"

${GS} -f ${INFILE}
database $

実行権限を与えて実行する

chmod a+x eps_to_png
./eps_to_png hoge.eps