Sha256: 712cadd1d8ced542cfa72a0f6227837fa241a061e8c80d576cfc7bf23d7a674f

Contents?: true

Size: 661 Bytes

Versions: 22

Compression:

Stored size: 661 Bytes

Contents

class FormatParser::PSDParser
  include FormatParser::IOUtils

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

  def likely_match?(filename)
    filename =~ /\.psd$/i # Maybe also PSB at some point
  end

  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

  FormatParser.register_parser new, natures: :image, formats: :psd
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
format_parser-0.26.0 lib/parsers/psd_parser.rb
format_parser-0.25.6 lib/parsers/psd_parser.rb
format_parser-0.25.5 lib/parsers/psd_parser.rb
format_parser-0.25.4 lib/parsers/psd_parser.rb
format_parser-0.25.3 lib/parsers/psd_parser.rb
format_parser-0.25.2 lib/parsers/psd_parser.rb
format_parser-0.25.1 lib/parsers/psd_parser.rb
format_parser-0.25.0 lib/parsers/psd_parser.rb
format_parser-0.24.2 lib/parsers/psd_parser.rb
format_parser-0.24.1 lib/parsers/psd_parser.rb
format_parser-0.24.0 lib/parsers/psd_parser.rb
format_parser-0.23.1 lib/parsers/psd_parser.rb
format_parser-0.23.0 lib/parsers/psd_parser.rb
format_parser-0.22.1 lib/parsers/psd_parser.rb
format_parser-0.22.0 lib/parsers/psd_parser.rb
format_parser-0.21.1 lib/parsers/psd_parser.rb
format_parser-0.21.0 lib/parsers/psd_parser.rb
format_parser-0.20.1 lib/parsers/psd_parser.rb
format_parser-0.20.0 lib/parsers/psd_parser.rb
format_parser-0.19.0 lib/parsers/psd_parser.rb