Class: FormatParser::PSDParser
- Inherits:
-
Object
- Object
- FormatParser::PSDParser
- Includes:
- IOUtils
- Defined in:
- lib/parsers/psd_parser.rb
Constant Summary collapse
- PSD_HEADER =
[0x38, 0x42, 0x50, 0x53]
- PSD_MIME_TYPE =
'application/x-photoshop'
Instance Method Summary collapse
Methods included from IOUtils
Instance Method Details
#call(io) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/parsers/psd_parser.rb', line 11 def call(io) io = FormatParser::IOConstraint.new(io) magic_bytes = safe_read(io, 4).unpack('C4') return unless magic_bytes == PSD_HEADER # We can be reasonably certain this is a PSD so we grab the height # and width bytes w, h = safe_read(io, 22).unpack('x10N2') FormatParser::Image.new( format: :psd, width_px: w, height_px: h, content_type: PSD_MIME_TYPE, ) end |
#likely_match?(filename) ⇒ Boolean
7 8 9 |
# File 'lib/parsers/psd_parser.rb', line 7 def likely_match?(filename) filename =~ /\.psd$/i # Maybe also PSB at some point end |