class ChunkyPNG::Chunk::Physical

The Physical (pHYs) chunk specifies the intended pixel size or aspect ratio for display of the image.

@see www.w3.org/TR/PNG/#11pHYs

Constants

INCHES_PER_METER

Attributes

ppux[RW]
ppuy[RW]
unit[RW]

Public Class Methods

new(ppux, ppuy, unit = :unknown) click to toggle source
Calls superclass method ChunkyPNG::Chunk::Base.new
# File lib/chunky_png/chunk.rb, line 364
def initialize(ppux, ppuy, unit = :unknown)
  raise ArgumentError, "unit must be either :meters or :unknown" unless [:meters, :unknown].member?(unit)
  super("pHYs")
  @ppux, @ppuy, @unit = ppux, ppuy, unit
end
read(type, content) click to toggle source
# File lib/chunky_png/chunk.rb, line 380
def self.read(type, content)
  ppux, ppuy, unit = content.unpack("NNC")
  unit = unit == 1 ? :meters : :unknown
  new(ppux, ppuy, unit)
end

Public Instance Methods

content() click to toggle source

Assembles the content to write to the stream for this chunk. @return [String] The binary content that should be written to the datastream.

# File lib/chunky_png/chunk.rb, line 388
def content
  [ppux, ppuy, unit == :meters ? 1 : 0].pack("NNC")
end
dpix() click to toggle source
# File lib/chunky_png/chunk.rb, line 370
def dpix
  raise ChunkyPNG::UnitsUnknown, "the PNG specifies its physical aspect ratio, but does not specify the units of its pixels' physical dimensions" unless unit == :meters
  ppux * INCHES_PER_METER
end
dpiy() click to toggle source
# File lib/chunky_png/chunk.rb, line 375
def dpiy
  raise ChunkyPNG::UnitsUnknown, "the PNG specifies its physical aspect ratio, but does not specify the units of its pixels' physical dimensions" unless unit == :meters
  ppuy * INCHES_PER_METER
end