Class: PictureTag::Parsers::ImageBackend
- Inherits:
-
Object
- Object
- PictureTag::Parsers::ImageBackend
- Defined in:
- lib/jekyll_picture_tag/parsers/image_backend.rb
Overview
Returns information regarding image handlers
Instance Method Summary collapse
-
#all_names(format) ⇒ Object
Returns an array of all known names of a format, for the purposes of parsing supported output formats.
- #handler_for(format) ⇒ Object
-
#magick_formats ⇒ Object
Returns an array of formats that imagemagick can handle.
-
#vips_formats ⇒ Object
Returns array of formats that vips can save to.
Instance Method Details
#all_names(format) ⇒ Object
Returns an array of all known names of a format, for the purposes of parsing supported output formats.
50 51 52 53 |
# File 'lib/jekyll_picture_tag/parsers/image_backend.rb', line 50 def all_names(format) alts = alternates.select { |a| a.include? format }.flatten alts.any? ? alts : [format] end |
#handler_for(format) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/jekyll_picture_tag/parsers/image_backend.rb', line 5 def handler_for(format) if (vips_formats & all_names(format)).any? :vips elsif (magick_formats & all_names(format)).any? :magick else raise error_string(format) end end |
#magick_formats ⇒ Object
Returns an array of formats that imagemagick can handle.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jekyll_picture_tag/parsers/image_backend.rb', line 30 def magick_formats if command?('magick') @magick_formats ||= `magick -version` .scan(/Delegates.*/) .first .delete_prefix('Delegates (built-in):') .split elsif command?('convert') @magick_formats ||= `convert -version` .scan(/Delegates.*/) .first .delete_prefix('Delegates (built-in):') .split else @magick_formats = [] end end |
#vips_formats ⇒ Object
Returns array of formats that vips can save to
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/jekyll_picture_tag/parsers/image_backend.rb', line 16 def vips_formats if command?('vips') @vips_formats ||= `vips -l` .split('/n') .select { |line| line.include? 'ForeignSave' } .flat_map { |line| line.scan(/\.[a-z]{1,5}/) } .map { |format| format.strip.delete_prefix('.') } .uniq else @vips_formats = [] end end |