Class: ChunkyPNG::Chunk::Text

Inherits:
Base
  • Object
show all
Defined in:
lib/chunky_png/chunk.rb

Overview

The Text (tEXt) chunk contains keyword/value metadata about the PNG stream. In this chunk, the value is stored uncompressed.

The tEXt chunk only supports Latin-1 encoded textual data. If you need UTF-8 support, check out the InternationalText chunk type.

Instance Attribute Summary collapse

Attributes inherited from Base

#type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#write, #write_with_crc

Constructor Details

#initialize(keyword, value) ⇒ Text

Returns a new instance of Text.



273
274
275
276
# File 'lib/chunky_png/chunk.rb', line 273

def initialize(keyword, value)
  super('tEXt')
  @keyword, @value = keyword, value
end

Instance Attribute Details

#keywordObject

Returns the value of attribute keyword.



271
272
273
# File 'lib/chunky_png/chunk.rb', line 271

def keyword
  @keyword
end

#valueObject

Returns the value of attribute value.



271
272
273
# File 'lib/chunky_png/chunk.rb', line 271

def value
  @value
end

Class Method Details

.read(type, content) ⇒ Object



278
279
280
281
# File 'lib/chunky_png/chunk.rb', line 278

def self.read(type, content)
  keyword, value = content.unpack('Z*a*')
  new(keyword, value)
end

Instance Method Details

#contentObject

Creates the content to write to the stream, by concatenating the keyword with the value, joined by a null character.

Returns:

  • The content that should be written to the datastream.



287
288
289
# File 'lib/chunky_png/chunk.rb', line 287

def content
  [keyword, value].pack('Z*a*')
end