Class: ChunkyPNG::Image

Inherits:
Canvas
  • Object
show all
Defined in:
lib/chunky_png/image.rb

Overview

Image class

Constant Summary collapse

METADATA_COMPRESSION_TRESHOLD =
300

Instance Attribute Summary collapse

Attributes inherited from Canvas

#height, #pixels, #width

Attributes included from Canvas::PNGDecoding

#decoding_palette

Attributes included from Canvas::PNGEncoding

#encoding_palette

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Canvas

#[], #[]=, #eql?, from_canvas, #include?, #palette, #size, #to_image

Methods included from Canvas::PNGDecoding

#decode_png_pixelstream, #from_blob, #from_datastream, #from_file, #from_io

Methods included from Canvas::Adam7Interlacing

#adam7_extract_pass, #adam7_merge_pass, #adam7_multiplier_offset, #adam7_pass_size, #adam7_pass_sizes

Methods included from Canvas::StreamImporting

#from_abgr_stream, #from_bgr_stream, #from_rgb_stream, #from_rgba_stream

Methods included from Canvas::Drawing

#line_xiaolin_wu, #point

Methods included from Canvas::Operations

#change_mask_color!, #change_theme_color!, #compose, #crop, #extract_mask, #replace

Methods included from Canvas::StreamExporting

#to_abgr_stream, #to_rgb_stream, #to_rgba_stream

Methods included from Canvas::PNGEncoding

#save, #to_blob, #write

Constructor Details

#initialize(width, height, initial = ChunkyPNG::Color::TRANSPARENT, metadata = {}) ⇒ Image

Returns a new instance of Image.



11
12
13
14
15
# File 'lib/chunky_png/image.rb', line 11

def initialize(width, height, initial = ChunkyPNG::Color::TRANSPARENT,  = {})
  super(width, height, initial)
  @metadata = 
  @metadata_compression_treshhold = 300
end

Instance Attribute Details

#metadataObject

Returns the value of attribute metadata.



9
10
11
# File 'lib/chunky_png/image.rb', line 9

def 
  @metadata
end

Class Method Details

.from_datastream(ds) ⇒ Object



38
39
40
41
42
# File 'lib/chunky_png/image.rb', line 38

def self.from_datastream(ds)
  image = super(ds)
  image. = ds.
  return image
end

Instance Method Details

#initialize_copy(other) ⇒ Object



17
18
19
20
# File 'lib/chunky_png/image.rb', line 17

def initialize_copy(other)
  super(other)
  @metdata = other.
end

#metadata_chunksObject



22
23
24
25
26
27
28
29
30
# File 'lib/chunky_png/image.rb', line 22

def 
  .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

#to_datastream(constraints = {}) ⇒ Object



32
33
34
35
36
# File 'lib/chunky_png/image.rb', line 32

def to_datastream(constraints = {})
  ds = super(constraints)
  ds.other_chunks += 
  return ds
end