Class: Markdownator::Converters::Image
- Defined in:
- lib/markdownator/converters/image.rb
Overview
Converts an image into Markdown metadata (filename + EXIF fields). When a captioner is supplied via the ‘captioner:` option, its description is appended. A captioner is any object responding to `#caption(io, stream_info) -> String`.
Constant Summary collapse
- EXTENSIONS =
%w[jpg jpeg png gif tif tiff].freeze
- MIMETYPES =
%w[image/jpeg image/png image/gif image/tiff].freeze
- EXIF_FIELDS =
EXIF fields worth surfacing, in display order.
%i[ date_time make model orientation f_number exposure_time iso_speed_ratings focal_length gps_latitude gps_longitude image_description ].freeze
Instance Method Summary collapse
Instance Method Details
#accepts?(_io, stream_info) ⇒ Boolean
20 21 22 |
# File 'lib/markdownator/converters/image.rb', line 20 def accepts?(_io, stream_info) matches?(stream_info, extensions: EXTENSIONS, mimetypes: MIMETYPES) end |
#convert(io, stream_info, **options) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/markdownator/converters/image.rb', line 24 def convert(io, stream_info, **) lines = [] lines << "# #{stream_info.filename}" if stream_info.filename = (io, stream_info) .each { |key, value| lines << "- **#{key}**: #{value}" } caption = caption_for(io, stream_info, [:captioner]) lines << "\n#{caption}" if caption Result.new(markdown: lines.join("\n").strip, metadata: ) end |