Class: FormatParser::PSDParser

Inherits:
Object
  • Object
show all
Includes:
IOUtils
Defined in:
lib/parsers/psd_parser.rb

Constant Summary collapse

PSD_HEADER =
[0x38, 0x42, 0x50, 0x53]

Instance Method Summary collapse

Methods included from IOUtils

#safe_read, #safe_skip

Instance Method Details

#call(io) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/parsers/psd_parser.rb', line 6

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,
  )
end