Class: DynamicImage::ImageReader

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamic_image/image_reader.rb

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ ImageReader


5
6
7
# File 'lib/dynamic_image/image_reader.rb', line 5

def initialize(data)
  @data = data
end

Instance Method Details

#readObject


9
10
11
12
# File 'lib/dynamic_image/image_reader.rb', line 9

def read
  raise DynamicImage::Errors::InvalidHeader unless valid_header?
  MiniMagick::Image.read(@data)
end

#valid_header?Boolean


14
15
16
17
18
19
20
# File 'lib/dynamic_image/image_reader.rb', line 14

def valid_header?
  return false if file_header.blank?
  magic_bytes.each do |str|
    return true if file_header.start_with?(str)
  end
  false
end