LoginSignup
7
7

More than 5 years have passed since last update.

ImageMagickでPDFを変換できるようにする。

Last updated at Posted at 2016-11-27

CarrierWaveとMinimagickを利用して、アップロードしたPDFファイルを画像変換させようとしたところ、次のようなエラーが出る。

Failed to manipulate with MiniMagick, maybe it is not an image? Original Error: `identify /var/folders/_l/9yzlbg193032kq9tqz206j4j_d7vyd/T/mini_magick20161127-92446-1sstieq.pdf
` failed with error:

調べてみるとminimagickではなく、ImageMagickがPDFに対応できていないことが問題だった。
ここでは、Mac上でPDFをImageMagickが扱えるようにする手順を紹介する。

事前確認

インストールしているImageMagickがPDFを扱えないことを確認する。

$ idnetify /path/to/sample.pdf
$ echo $?
1  # <= Failed

手順

今のImageMagickをアンインストール

brew uninstallでアンインストールします。

$ brew uninstall imagemagick

これまでインストールしてきた過去のバージョン全てをここでアンインストールする必要はありませんが、きれいにするなら今でしょう。

GhostScriptをインストール

PDFを扱えるようにするために、ghostscriptをインストールします。

$ brew install ghostscript

ImageMagickをソースから再インストール

再インストールしたら完了。

$ brew install imagemagick --build-from-source

確認

identifyコマンドを使って、PDFファイルの情報が取得できればOK。

$ idnetify /path/to/sample.pdf
/path/to/sample.pdf PDF 595x842 595x842+0+0 16-bit sRGB 3.85KB 0.000u 0:00.000
7
7
2

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