class ChunkyPNG::Image

@see ChunkyPNG::Canvas
also includes support for metadata.
ChunkyPNG::Image is an extension of the {ChunkyPNG::Canvas} class, that

def self.from_datastream(ds)

Parameters:
  • ds (ChunkyPNG::Datastream) -- The datastream to read from.
def self.from_datastream(ds)
  image = super(ds)
  image.metadata = ds.metadata
  image
end

def initialize(width, height, bg_color = ChunkyPNG::Color::TRANSPARENT, metadata = {})

Other tags:
    See: ChunkyPNG::Canvas#initialize -

Parameters:
  • metadata (Hash) -- A hash of metadata fields and values for this image.
  • bg_color (Integer) -- The background color of the new image.
  • height (Integer) -- The height of the new image.
  • width (Integer) -- The width of the new image.
def initialize(width, height, bg_color = ChunkyPNG::Color::TRANSPARENT, metadata = {})
  super(width, height, bg_color)
  @metadata = metadata
end

def initialize_copy(other)

Parameters:
  • other (ChunkyPNG::Image) -- The other image to copy.
def initialize_copy(other)
  super(other)
  @metadata = other.metadata
end

def metadata_chunks

Other tags:
    See: ChunkyPNG::Image::METADATA_COMPRESSION_TRESHOLD -

Returns:
  • (Array) - An array of metadata chunks.
def metadata_chunks
  metadata.map do |key, value|
    if value.length >= METADATA_COMPRESSION_TRESHOLD
      ChunkyPNG::Chunk::CompressedText.new(key, value)
    else
      ChunkyPNG::Chunk::Text.new(key, value)
    end
  end
end

def to_datastream(constraints = {})

Other tags:
    See: #metadata_chunks -
    See: ChunkyPNG::Canvas::PNGEncoding#to_datastream -

Returns:
  • (ChunkyPNG::Datastream) - The datastream that contains this image.

Parameters:
  • constraints (Hash) -- The constraints to use when encoding the canvas.
def to_datastream(constraints = {})
  ds = super(constraints)
  ds.other_chunks += metadata_chunks
  ds
end