westonplatter / phashion

Ruby wrapper around pHash, the perceptual hash library for detecting duplicate multimedia files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RuntimeError: Unknown pHash error on MAC OS X

aonu opened this issue · comments

I am having the following error when I tried to use the library:

2.3.3 :004 > img1 = Phashion::Image.new('/Users/adrianonu/Docker/a1.jpg')
 => #<Phashion::Image:0x007f84ce8ba510 @filename="/Users/aa/Docker/dormitor1.jpg"> 
2.3.3 :005 > img2 = Phashion::Image.new('/Users/adrianonu/Docker/dormitor2.jpg')
 => #<Phashion::Image:0x007f84ce870c80 @filename="/Users/aa/Docker/a2.jpg"> 
2.3.3 :006 > img1.duplicate?(img2)
convert: delegate failed `'dwebp' -pam '%i' -o '%o'' @ error/delegate.c/InvokeDelegate/1845.
convert: unable to open file '/var/folders/r6/vjwjz3xd3r928qnctprt32ch0000gn/T/magick-40735nzCZw9BST4fv': No such file or directory @ error/constitute.c/ReadImage/549.
convert: no images defined `pnm:-' @ error/convert.c/ConvertImageCommand/3254.
sh: gm: command not found
RuntimeError: Unknown pHash error

Anyone had a similar issue?

Thanks!

@aonu Thanks for submitting an issue. Which version of ruby and the gem are you using?

Had almost the same errors:

convert: unable to load module '/usr/local/Cellar/imagemagick/7.0.6-5_2/lib/ImageMagick//modules-Q16HDRI/coders/jpeg.la': file not found @ error/module.c/OpenModule/1266.
convert: no decode delegate for this image format `JPEG' @ error/constitute.c/ReadImage/509.
convert: no images defined `pnm:-' @ error/convert.c/ConvertImageCommand/3275.
sh: gm: command not found

Fixed by:

brew uninstall jpeg
brew uninstall imagemagick
gem uninstall phashion

brew install jpeg
brew install imagemagick
brew install jpeg
gem install phashion

Also i noticed that libjpeg recently changed version from 8b to 9b. Maybe this is the core of this issue.

@mrThe thanks for suggesting a fix. @aonu does this work for you? If not, happy to look at finding the root cause with you.

We're having this issue a lot with broken image files (dockerized linux).

[1] pry(main)> img = Phashion::Image.new("broken_image.jpg")
=> #<Phashion::Image:0x0000000005702150 @filename="broken_image.jpg">
[2] pry(main)> img.fingerprint
convert: insufficient image data in file `broken_image.jpg' @ error/jpeg.c/ReadJPEGImage/1039.
convert: no images defined `pnm:-' @ error/convert.c/ConvertImageCommand/3210.
sh: 1: gm: not found
RuntimeError: Unknown pHash error
from /cache/artisan/bundle/gems/phashion-1.2.0/lib/phashion.rb:39:in `image_hash_for'

Note that raising an error here is great, but it would be nice if it wouldn't be a generic RuntimeError.

In addition, mh_fingerprint on the same image does a core dump and kills the active process:

[3] pry(main)> img.mh_fingerprint
convert: insufficient image data in file `broken_image.jpg' @ error/jpeg.c/ReadJPEGImage/1039.
convert: no images defined `pnm:-' @ error/convert.c/ConvertImageCommand/3210.
sh: 1: gm: not found
terminate called after throwing an instance of 'cimg_library::CImgIOException'
  what():  [instance(0,0,0,0,(nil),non-shared)] CImg<unsigned char>::load() : Failed to recognize format of file 'broken_image.jpg'.
Aborted (core dumped)

EDIT: Noticed this has already been brought up in #67

Creating a broken image is simple, just create an empty file via bash: touch broken_image.jpg

For reference, here's my versions of dependencies:

  • imagemagick at 8:6.8.9.9-7ubuntu5.9
  • libjpeg8 at 8c-2ubuntu8