Sha256: 2a66a4bbf5a11b187dcd764d81e52ee208ce5ab484fa5ab754f4ff6b6290f026

Contents?: true

Size: 740 Bytes

Versions: 35

Compression:

Stored size: 740 Bytes

Contents

class FormatParser::PSDParser
  include FormatParser::IOUtils

  PSD_HEADER = [0x38, 0x42, 0x50, 0x53]
  PSD_MIME_TYPE = 'application/x-photoshop'

  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,
      content_type: PSD_MIME_TYPE,
    )
  end

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

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
format_parser-2.10.0 lib/parsers/psd_parser.rb
format_parser-2.9.0 lib/parsers/psd_parser.rb
format_parser-2.8.0 lib/parsers/psd_parser.rb
format_parser-2.7.2 lib/parsers/psd_parser.rb
format_parser-2.7.1 lib/parsers/psd_parser.rb
format_parser-2.7.0 lib/parsers/psd_parser.rb
format_parser-2.6.0 lib/parsers/psd_parser.rb
format_parser-2.5.0 lib/parsers/psd_parser.rb
format_parser-2.4.5 lib/parsers/psd_parser.rb
format_parser-2.4.4 lib/parsers/psd_parser.rb
format_parser-2.4.3 lib/parsers/psd_parser.rb
format_parser-2.3.0 lib/parsers/psd_parser.rb
format_parser-2.2.1 lib/parsers/psd_parser.rb
format_parser-2.2.0 lib/parsers/psd_parser.rb
format_parser-2.1.0 lib/parsers/psd_parser.rb
format_parser-2.0.0 lib/parsers/psd_parser.rb
format_parser-2.0.0.pre.4 lib/parsers/psd_parser.rb
format_parser-2.0.0.pre.3 lib/parsers/psd_parser.rb
format_parser-2.0.0.pre.2 lib/parsers/psd_parser.rb
format_parser-2.0.0.pre lib/parsers/psd_parser.rb