Sha256: 31a168e16de0edbe3aa716964683bc14752275d731e7d816e3c6c2178e8eba54

Contents?: true

Size: 986 Bytes

Versions: 15

Compression:

Stored size: 986 Bytes

Contents

module ChunkyPNG

  # Image class
  #
  class Image < Canvas

    METADATA_COMPRESSION_TRESHOLD = 300
    
    attr_accessor :metadata
    
    def initialize(width, height, initial = ChunkyPNG::Color::TRANSPARENT, metadata = {})
      super(width, height, initial)
      @metadata = metadata
      @metadata_compression_treshhold = 300
    end
    
    def initialize_copy(other)
      super(other)
      @metdata = other.metadata
    end
    
    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 = {})
      ds = super(constraints)
      ds.other_chunks += metadata_chunks
      return ds
    end
    
    def self.from_datastream(ds)
      image = super(ds)
      image.metadata = ds.metadata
      return image
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
chunky_png-0.9.0 lib/chunky_png/image.rb
chunky_png-0.8.0 lib/chunky_png/image.rb
chunky_png-0.7.3 lib/chunky_png/image.rb
chunky_png-0.7.1 lib/chunky_png/image.rb
chunky_png-0.7.0 lib/chunky_png/image.rb
chunky_png-0.6.0 lib/chunky_png/image.rb
chunky_png-0.5.8 lib/chunky_png/image.rb
chunky_png-0.5.7 lib/chunky_png/image.rb
chunky_png-0.5.6 lib/chunky_png/image.rb
chunky_png-0.5.5 lib/chunky_png/image.rb
chunky_png-0.5.4 lib/chunky_png/image.rb
chunky_png-0.5.3 lib/chunky_png/image.rb
chunky_png-0.5.2 lib/chunky_png/image.rb
chunky_png-0.5.1 lib/chunky_png/image.rb
chunky_png-0.5.0 lib/chunky_png/image.rb