Class: ChunkyPNG::Chunk::Physical
Overview
The Physical (pHYs) chunk specifies the intended pixel size or aspect ratio for display of the image.
Constant Summary collapse
- INCHES_PER_METER =
0.0254
Instance Attribute Summary collapse
-
#ppux ⇒ Object
Returns the value of attribute ppux.
-
#ppuy ⇒ Object
Returns the value of attribute ppuy.
-
#unit ⇒ Object
Returns the value of attribute unit.
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
-
#content ⇒ String
Assembles the content to write to the stream for this chunk.
- #dpix ⇒ Object
- #dpiy ⇒ Object
-
#initialize(ppux, ppuy, unit = :unknown) ⇒ Physical
constructor
A new instance of Physical.
Methods inherited from Base
Constructor Details
#initialize(ppux, ppuy, unit = :unknown) ⇒ Physical
Returns a new instance of Physical.
329 330 331 332 333 |
# File 'lib/chunky_png/chunk.rb', line 329 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 |
Instance Attribute Details
#ppux ⇒ Object
Returns the value of attribute ppux.
327 328 329 |
# File 'lib/chunky_png/chunk.rb', line 327 def ppux @ppux end |
#ppuy ⇒ Object
Returns the value of attribute ppuy.
327 328 329 |
# File 'lib/chunky_png/chunk.rb', line 327 def ppuy @ppuy end |
#unit ⇒ Object
Returns the value of attribute unit.
327 328 329 |
# File 'lib/chunky_png/chunk.rb', line 327 def unit @unit end |
Class Method Details
.read(type, content) ⇒ Object
345 346 347 348 349 |
# File 'lib/chunky_png/chunk.rb', line 345 def self.read(type, content) ppux, ppuy, unit = content.unpack('NNC') unit = unit == 1 ? :meters : :unknown new(ppux, ppuy, unit) end |
Instance Method Details
#content ⇒ String
Assembles the content to write to the stream for this chunk.
353 354 355 |
# File 'lib/chunky_png/chunk.rb', line 353 def content [ppux, ppuy, unit == :meters ? 1 : 0].pack('NNC') end |
#dpix ⇒ Object
335 336 337 338 |
# File 'lib/chunky_png/chunk.rb', line 335 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 ⇒ Object
340 341 342 343 |
# File 'lib/chunky_png/chunk.rb', line 340 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 |