Sha256: 47337fc079b1392c00170047b2b54a4bc988052ae2f06f0dbd74390154c55ef6

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

module PictureTag
  module Parsers
    # Returns information regarding image handlers
    class ImageBackend
      def handler_for(format)
        if vips_formats.include? format
          :vips
        elsif magick_formats.include? format
          :magick
        else
          raise "No support for generating #{format} files in this environment."
        end
      end

      # Returns array of formats that vips can save to
      def vips_formats
        @vips_formats ||= `vips -l filesave`
                          .scan(/\.[a-z]{1,5}/)
                          .uniq
                          .map { |format| format.strip.delete_prefix('.') }
      end

      # Returns an array of formats that imagemagick can handle.
      def magick_formats
        @magick_formats ||= `convert -version`
                            .split("\n")
                            .last
                            .delete_prefix('Delegates (built-in):')
                            .split
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll_picture_tag-2.0.2 lib/jekyll_picture_tag/parsers/image_backend.rb
jekyll_picture_tag-2.0.1 lib/jekyll_picture_tag/parsers/image_backend.rb