Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

identify parser does not handle a set, such as IPTC Keywords. #3

Closed
cwholt opened this issue Sep 10, 2014 · 2 comments
Closed

identify parser does not handle a set, such as IPTC Keywords. #3

cwholt opened this issue Sep 10, 2014 · 2 comments

Comments

@cwholt
Copy link

cwholt commented Sep 10, 2014

using this code:

require 'tempfile'
require 'open-uri'
require 'micro_magick'

onion_url = "http://www.photometadata.org/sites/default/files/farmer_onion.jpg"

tf = Tempfile.new(%w{ onion_farmer .jpg })
tf.binmode
open(onion_url, {}) { |bits| tf.write(bits.read) }
final_cmd = "identify -verbose #{tf.path}"
stdout = Open3.popen3(final_cmd) do |stdin, stdout, stderr|
  stdout.read.strip
end
tf.close
tf.unlink
results = MicroMagick::IdentifyParser.new(stdout)
results[:profiles][:profile_iptc][:keyword_2_25_] # "Leeks"

However, this example file should have 45 keywords!

MicroMagick::IdentifyParser simply sets the last seen key

but it should create an array.

@mceachen
Copy link
Owner

Thanks for the great report, and sorry for the response latency.

You should definitely look at the exiftool and exiftool_vendored gems. They work together so you have one less thing to worry about installing and upgrading on your servers. Graphicsmagick and Imagemagick's identify support is much less impressive when compared to exiftool (and the exiftool gem supports fetching multiple files in one call, which can be dramatically more efficient).

Here's your use case:

irb(main):001:0> require 'exiftool_vendored'
=> true
irb(main):002:0> Exiftool.new('farmer_onion.jpg').to_hash[:subject]
=> ["white", "outdoors", "vegetables", "male", "caucasian", "outside", "horizontal", "Person", "plants", "Agriculture", "Crops", "tractor", "outdoor", "conceptual", "organic", "farmer", "concept", "agronomy", "crop", "concepts", "abundance", "repetition", "granger", "farmhand", "farm hand", "field hand", "farm laborer", "field worker", "human", "human being", "human beings", "humans", "white person", "masculine", "30-55 years old", "onions", "vegetable crops", "agricultural equipment", "horizontals", "able-bodied", "farm fresh", "sustainable agriculture", "organic farming", "organics", "Leeks"]

I'll pull this now, though.

@mceachen
Copy link
Owner

mceachen commented Sep 7, 2015

I've just released v1.0.0 which greatly simplifies identify parsing to only support dimensions (which is required by the other functions. All the other attributes, like EXIF headers, were pretty hacky—no correct types, nesting was inconsistent, and paths changed across versions of ImageMagick and GraphicsMagick.

I've updated the README to point people to the exiftool and exiftool_vendored gems for this use case.

@mceachen mceachen closed this as completed Sep 7, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants