Class: OggAlbumTagger::Picture
- Inherits:
-
Object
- Object
- OggAlbumTagger::Picture
- Defined in:
- lib/ogg_album_tagger/picture.rb
Class Method Summary collapse
-
.generate_metadata_block_picture(image, desc = '') ⇒ Object
Embed a picture so that it can be included as a tag.
Class Method Details
.generate_metadata_block_picture(image, desc = '') ⇒ Object
Embed a picture so that it can be included as a tag.
See xiph.org/flac/format.html#metadata_block_picture Note: the type of the picture is currently fixed to “Front cover”, as it is the most common type.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ogg_album_tagger/picture.rb', line 13 def self.(image, desc = '') begin image = File.(image) img = Exiftool.new(image) content = IO.binread(image) rescue Exiftool::ExiftoolNotInstalled raise OggAlbumTagger::SystemError, "exiftool (the executable, not the gem) is not in your path, please install it." rescue raise OggAlbumTagger::ArgumentError, "\"#{image}\" cannot be read." end = img.results[0].to_hash mime = [:mime_type] raise OggAlbumTagger::ArgumentError, 'Unsupported image type. Use JPEG or PNG.' unless ['image/png', 'image/jpeg'].include?(mime) pack = [ 3, # Front cover mime.length, mime, desc.bytesize, desc, [:image_width], [:image_height], [:color_components] * [:bits_per_sample], 0, # palette content.length, content ].pack(sprintf("L>L>A%dL>a%dL>L>L>L>L>a*", mime.length, desc.bytesize)) Base64.strict_encode64(pack) end |