1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ImageMagickで compare: image widths or heights differ と出た場合

1
Last updated at Posted at 2019-02-23

結論

最新のバージョンのImageMagickをインストールする

現象

a.pngb.png があり、diff.png を作成しようとして、「画像の幅か高さが違う!」と怒られる。

# compare ./a.jpg ./b.jpg diff.jpg
compare: image widths or heights differ `./a.jpg' @ error/compare.c/CompareImageCommand/964.

経緯

自宅で仮作成したプログラムを会社に持っていったら上記エラー発生。
該当エラーで検索しても、サイズが違うとできないという記事ばかりヒット。
ただ自宅で作ったのはMac環境で、サイズが異なる画像でも比較画像が作成できていた。
会社のLinux環境(CentOS)では、上記エラーが出たことで、問題の切り分けを行った。

まずは、エラーが起こらないMacOSでのバージョンを確認。

# compare --version
Version: ImageMagick 7.0.8-28 Q16 x86_64 2019-02-19 https://imagemagick.org}

次に、エラーが起こるCentOSでのバージョンを確認。

# compare -version
Version: ImageMagick 6.7.8-9 2016-06-16 Q16 http://www.imagemagick.org

CentOSのyumでインストールを試みると、19.2.22時点で、Ver. 6.7.8.9-15.el7_2 がインストールされるが、どうやらこのバージョンでは、サイズ差がある場合、補完してくれるわけではない様子。

最新のバージョンをインストールする

remi レポジトリーを追加し、ImageMagick7をインストールする

# yum install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# yum install imagemagick7 --enablerepo=remi
# compare --version
Version: ImageMagick 7.0.8-28 Q16 x86_64 2019-02-18 https://imagemagick.org
Copyright: © 1999-2019 ImageMagick Studio LLC

これで、サイズの異なる画像でも画像比較などの処理が可能になる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?