lib/chunky_png/canvas/png_encoding.rb
# Converts this Canvas to a datastream, so that it can be saved as a PNG image.
# @param [Hash, Symbol] constraints The constraints to use when encoding the canvas.
#    This can either be a hash with different constraints, or a symbol which acts as a
#    preset for some constraints. If no constraints are given, ChunkyPNG will decide
#    for itself how to best create the PNG datastream.
#    Supported presets are <tt>:fast_rgba</tt> for quickly saving images with transparency,
#    <tt>:fast_rgb</tt> for quickly saving opaque images, and <tt>:best_compression</tt> to
#    obtain the smallest possible filesize.
# @option constraints [Fixnum] :color_mode The color mode to use. Use one of the
#    ChunkyPNG::COLOR_* constants.
# @option constraints [true, false] :interlace Whether to use interlacing.
# @option constraints [Fixnum] :compression The compression level for Zlib. This can be a
#    value between 0 and 9, or a Zlib constant like Zlib::BEST_COMPRESSION.
# @option constraints [Fixnum] :bit_depth The bit depth to use. This option is only used
#    for indexed images, in which case it overrides the determined minimal bit depth. For
#    all the other color modes, a bit depth of 8 is used.
# @return [ChunkyPNG::Datastream] The PNG datastream containing the encoded canvas.
# @see ChunkyPNG::Canvas::PNGEncoding#determine_png_encoding
Converts this Canvas to a datastream, so that it can be saved as a PNG image.
Converts this Canvas to a datastream so that it can be saved as a PNG image .
def to_datastream(constraints = {})
        encoding = determine_png_encoding(constraints)
        ds = Datastream.new
        ds.header_chunk = Chunk::Header.new(
          width: width,
          height: height,
          color: encoding[:color_mode],
          depth: encoding[:bit_depth],
          interlace: encoding[:interlace]
        )
        if encoding[:color_mode] == ChunkyPNG::COLOR_INDEXED
          ds.palette_chunk      = encoding_palette.to_plte_chunk
          ds.transparency_chunk = encoding_palette.to_trns_chunk unless encoding_palette.opaque?
        end
        data           = encode_png_pixelstream(encoding[:color_mode], encoding[:bit_depth], encoding[:interlace], encoding[:filtering])
        ds.data_chunks = Chunk::ImageData.split_in_chunks(data, encoding[:compression])
        ds.end_chunk   = Chunk::End.new
        ds
      end
def to_datastream ( constraints = { } ) encoding = determine_png_encoding ( constraints ) ds = Datastream . new ds . header_chunk = Chunk :: Header . new ( width : width , height : height , color : encoding [ :color_mode ] , depth : encoding [ :bit_depth ] , interlace : encoding [ :interlace ] ) if encoding [ :color_mode ] == ChunkyPNG :: COLOR_INDEXED ds . palette_chunk = encoding_palette . to_plte_chunk ds . transparency_chunk = encoding_palette . to_trns_chunk unless encoding_palette . opaque? end data = encode_png_pixelstream ( encoding [ :color_mode ] , encoding [ :bit_depth ] , encoding [ :interlace ] , encoding [ :filtering ] ) ds . data_chunks = Chunk :: ImageData . split_in_chunks ( data , encoding [ :compression ] ) ds . end_chunk = Chunk :: End . new ds end
Converts this Canvas to a datastream, so that it can be saved as a PNG image.
Converts this Canvas to a datastream so that it can be saved as a PNG image .
The PNG datastream containing the encoded canvas.
The PNG datastream containing the encoded canvas .
ChunkyPNG::Datastream
constraints
:bit_depth The bit depth to use. This option is only used for indexed images, in which case it overrides the determined minimal bit depth. For all the other color modes, a bit depth of 8 is used.
: bit_depth The bit depth to use . This option is only used for indexed images in which case it overrides the determined minimal bit depth . For all the other color modes a bit depth of 8 is used .
<not_specific>
constraints The constraints to use when encoding the canvas. This can either be a hash with different constraints, or a symbol which acts as a preset for some constraints. If no constraints are given, ChunkyPNG will decide for itself how to best create the PNG datastream. Supported presets are :fast_rgba for quickly saving images with transparency, :fast_rgb for quickly saving opaque images, and :best_compression to obtain the smallest possible filesize.
constraints The constraints to use when encoding the canvas . This can either be a hash with different constraints or a symbol which acts as a preset for some constraints . If no constraints are given ChunkyPNG will decide for itself how to best create the PNG datastream . Supported presets are : fast_rgba for quickly saving images with transparency : fast_rgb for quickly saving opaque images and : best_compression to obtain the smallest possible filesize .
see
None