class DynamicImage::Format
Attributes
Public Class Methods
Source
# File lib/dynamic_image/format.rb, line 34 def content_type(type) formats.filter { |f| f.content_types.include?(type) }.first end
Source
# File lib/dynamic_image/format.rb, line 38 def content_types formats.flat_map(&:content_types) end
Source
# File lib/dynamic_image/format.rb, line 42 def find(name) key = name.to_s.upcase key = "JPEG" if key == "JPG" registered_formats[key] end
Source
# File lib/dynamic_image/format.rb, line 48 def formats registered_formats.map { |_, f| f } end
Source
# File lib/dynamic_image/format.rb, line 8 def initialize(name, options) options = default_options.merge(options) @name = name @animated = options[:animated] @content_types = Array(options[:content_type]) @extensions = Array(options[:extension]) @magic_bytes = options[:magic_bytes].map do |s| s.dup.force_encoding("binary") end @save_options = options[:save_options] end
Source
# File lib/dynamic_image/format.rb, line 52 def register(name, **opts) registered_formats[name] = new(name, opts) end
Source
# File lib/dynamic_image/format.rb, line 56 def sniff(bytes) return unless bytes formats.each do |format| format.magic_bytes.each do |b| return format if bytes.start_with?(b) end end nil end
Private Class Methods
Source
# File lib/dynamic_image/format.rb, line 69 def registered_formats @registered_formats ||= {} end
Public Instance Methods
Source
# File lib/dynamic_image/format.rb, line 25 def content_type content_types.first end
Source
# File lib/dynamic_image/format.rb, line 74 def default_options { animated: false, content_type: [], extension: [], magic_bytes: [], save_options: {} } end