Class: DynamicImage::ImageReader
- Inherits:
-
Object
- Object
- DynamicImage::ImageReader
- Defined in:
- lib/dynamic_image/image_reader.rb
Class Method Summary collapse
Instance Method Summary collapse
- #exif ⇒ Object
-
#initialize(data) ⇒ ImageReader
constructor
A new instance of ImageReader.
- #read ⇒ Object
- #valid_header? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ ImageReader
Returns a new instance of ImageReader.
20 21 22 |
# File 'lib/dynamic_image/image_reader.rb', line 20 def initialize(data) @data = data end |
Class Method Details
.magic_bytes ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/dynamic_image/image_reader.rb', line 6 def magic_bytes @magic_bytes ||= [ "\x47\x49\x46\x38\x37\x61", # GIF "\x47\x49\x46\x38\x39\x61", "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a", # PNG "\xff\xd8", # JPEG "\x49\x49\x2a\x00", # TIFF "\x4d\x4d\x00\x2a", "\x42\x4d", # BMP "\x52\x49\x46\x46" # WEBP ].map { |s| s.dup.force_encoding("binary") } end |
Instance Method Details
#exif ⇒ Object
24 25 26 27 28 |
# File 'lib/dynamic_image/image_reader.rb', line 24 def exif raise DynamicImage::Errors::InvalidHeader unless valid_header? MiniExiftool.new(string_io) end |
#read ⇒ Object
30 31 32 33 34 |
# File 'lib/dynamic_image/image_reader.rb', line 30 def read raise DynamicImage::Errors::InvalidHeader unless valid_header? MiniMagick::Image.read(@data) end |
#valid_header? ⇒ Boolean
36 37 38 39 40 41 42 43 |
# File 'lib/dynamic_image/image_reader.rb', line 36 def valid_header? return false if file_header.blank? self.class.magic_bytes.each do |str| return true if file_header.start_with?(str) end false end |