class ChunkyPNG::Chunk::InternationalText

@see ChunkyPNG::Chunk::CompressedText
@see ChunkyPNG::Chunk::Text
@see www.w3.org/TR/PNG/#11iTXt<br><br>and uncompressed values.
a translation of the keyword name. Finally, it supports bot compressed
Moreover, it is possible to define the language of the metadata, and give
The metadata in this chunk can be encoded using UTF-8 characters.
stream, translated to a given locale.
The InternationalText (iTXt) chunk contains keyword/value metadata about the PNG

def self.read(type, content)

Raises:
  • (ChunkyPNG::NotSupported) - If the chunk refers to an unsupported compression method.
  • (ChunkyPNG::InvalidUTF8) - If the chunk contains data that is not UTF8-encoded text.

Returns:
  • (ChunkyPNG::Chunk::InternationalText) - The new End chunk instance.

Parameters:
  • content (String) -- The content read from the chunk.
  • type (String) -- The four character chunk type indicator (= "iTXt").
def self.read(type, content)
  keyword, compressed, compression, language_tag, translated_keyword, text = content.unpack("Z*CCZ*Z*a*")
  raise ChunkyPNG::NotSupported, "Compression flag #{compressed.inspect} not supported!" unless compressed == ChunkyPNG::UNCOMPRESSED_CONTENT || compressed == ChunkyPNG::COMPRESSED_CONTENT
  raise ChunkyPNG::NotSupported, "Compression method #{compression.inspect} not supported!" unless compression == ChunkyPNG::COMPRESSION_DEFAULT
  text = Zlib::Inflate.inflate(text) if compressed == ChunkyPNG::COMPRESSED_CONTENT
  text.force_encoding("utf-8")
  raise ChunkyPNG::InvalidUTF8, "Invalid unicode encountered in iTXt chunk" unless text.valid_encoding?
  translated_keyword.force_encoding("utf-8")
  raise ChunkyPNG::InvalidUTF8, "Invalid unicode encountered in iTXt chunk" unless translated_keyword.valid_encoding?
  new(keyword, text, language_tag, translated_keyword, compressed, compression)
end

def content

Returns:
  • (String) - The binary content that should be written to the datastream.
def content
  text_field = text.encode("utf-8")
  text_field = compressed == ChunkyPNG::COMPRESSED_CONTENT ? Zlib::Deflate.deflate(text_field) : text_field
  [keyword, compressed, compression, language_tag, translated_keyword.encode("utf-8"), text_field].pack("Z*CCZ*Z*a*")
end

def initialize(keyword, text, language_tag = "", translated_keyword = "", compressed = ChunkyPNG::UNCOMPRESSED_CONTENT, compression = ChunkyPNG::COMPRESSION_DEFAULT)

def initialize(keyword, text, language_tag = "", translated_keyword = "", compressed = ChunkyPNG::UNCOMPRESSED_CONTENT, compression = ChunkyPNG::COMPRESSION_DEFAULT)
  super("iTXt")
  @keyword = keyword
  @text = text
  @language_tag = language_tag
  @translated_keyword = translated_keyword
  @compressed = compressed
  @compression = compression
end