janfri/mini_exiftool

Handle binary metadata tags, especially ICC_Profile

cgat opened this issue · 3 comments

cgat commented

Perhaps this is out of the scope of mini_exiftool, but it would be great if mini_exiftool could support reading/writing of binary values.

More specifically, I am trying to assign an icc profile from one image to another. While I can read the icc profile subtags from the initial image using mini_exiftool (such as "ProfileCMMType", "ProfileVersion", "ProfileClass", "ProfileConnectionSpace", "ProfileDateTime", "ProfileFileSignature", "ProfileCreator", "ProfileID", "ProfileCopyright", "ProfileDescription"), these tags are non-writable. On the other hand, the ICC_Profile tag is writable, but I am not able to assign it the binary version of the ICC_Profile from the other image.

Thanks

cgat commented

On second thought, perhaps it would be easier to simply expose tagsFromFile into MiniExiftool. Something like:

def tags_from_file(src_path, opts={})
    overwrite = opts[:overwrite]==true ? '-overwrite_original' : ''
    tags_from_file_options = opts[:tags_from_file_options].present? ? opts[:tags_from_file_options] : ''
    run "#{MiniExiftool.command} -tagsFromFile #{src_path} #{tags_from_file_options} #{self.filename} #{overwrite}"
  end

Alternatively it could be a class method which takes in the source and destination as a parameter.

The above code might need some cleaning up though. At the moment its good enough for my application, but if you are interested I could make a pull request with a cleaner version and test when I get some time.

Let me know what you think.

Great idea and approach!

My solution is a little bit different: My method's name is MiniExiftool#copy_tags_from and has the following signature:

def copy_tags_from(source_filename, tags)

So I could use it the following ways:

require 'mini_exiftool'

photo = MiniExiftool.new('photo.jpg')

# Update the author tag of photo.jpg with the value of the author tag
# of another_photo.jpg
photo.copy_tags_from('another_photo.jpg', 'Author')

# It's also possible to use symbols and case is also not meaningful
photo.copy_tags_from('another_photo.jpg', :author)

# Further more than one tag can be copied at once
photo.copy_tags_from('another_photo', %w[author copyright])
end

Copying the ICC_Profile could then be written as

  photo = MiniExiftool.new(filename)
  photo.copy_tags_from(target, 'icc_profile')

Be aware: overwrite_originalis always set! I hope this helps you. I've just released mini_exiftool 2.4.0 with this new method included.

cgat commented

Awesome. What great timing! Thanks