Class: ChunkyPNG::Chunk::Transparency

### Home Classes Methods

### In Files

- lib/chunky_png/chunk.rb

### Parent

ChunkyPNG::Chunk::Generic

### Methods

- #grayscale_entry
- #palette_alpha_channel
- #truecolor_entry

### Files

- BENCHMARKING.rdoc
- CHANGELOG.rdoc
- CONTRIBUTING.rdoc
- README.rdoc

### Class/Module Index

Quicksearch

- ChunkyPNG
- ChunkyPNG::CRCMismatch
- ChunkyPNG::Canvas
- ChunkyPNG::Canvas::Adam7Interlacing
- ChunkyPNG::Canvas::DataUrlExporting
- ChunkyPNG::Canvas::DataUrlImporting
- ChunkyPNG::Canvas::Drawing
- ChunkyPNG::Canvas::Masking
- ChunkyPNG::Canvas::Operations
- ChunkyPNG::Canvas::PNGDecoding
- ChunkyPNG::Canvas::PNGEncoding
- ChunkyPNG::Canvas::Resampling
- ChunkyPNG::Canvas::StreamExporting
- ChunkyPNG::Canvas::StreamImporting
- ChunkyPNG::Chunk
- ChunkyPNG::Chunk::Base
- ChunkyPNG::Chunk::CompressedText
- ChunkyPNG::Chunk::End
- ChunkyPNG::Chunk::Generic
- ChunkyPNG::Chunk::Header
- ChunkyPNG::Chunk::ImageData
- ChunkyPNG::Chunk::InternationalText
- ChunkyPNG::Chunk::Palette
- ChunkyPNG::Chunk::Text
- ChunkyPNG::Chunk::Transparency
- ChunkyPNG::Color
- ChunkyPNG::Datastream
- ChunkyPNG::Dimension
- ChunkyPNG::Exception
- ChunkyPNG::ExpectationFailed
- ChunkyPNG::Image
- ChunkyPNG::NotSupported
- ChunkyPNG::OutOfBounds
- ChunkyPNG::Palette
- ChunkyPNG::Point
- ChunkyPNG::RMagick
- ChunkyPNG::SignatureMismatch
- ChunkyPNG::Vector
- Enumerable
- String

No matching classes.

# ChunkyPNG::Chunk::Transparency

A transparency (tRNS) chunk defines the transparency for an image.

- For indexed images, it contains the alpha channel for the colors defined in the Palette (PLTE) chunk.

- For grayscale images, it contains the grayscale teint that should be considered fully transparent.

- For truecolor images, it contains the color that should be considered fully transparent.

Images having a color mode that already includes an alpha channel, this chunk should not be included.

@see ChunkyPNG::Chunk::Palette @see ChunkyPNG::Palette

### Public Instance Methods

grayscale_entry(bit_depth) click to toggle source

Returns the grayscale entry to be replaced by transparent pixels.

This method should only be used for images having color mode ChunkyPNG::COLOR_GRAYSCALE (0).

@return [Integer] The (grayscale) color to replace with fully

    transparent pixels.

    # File lib/chunky_png/chunk.rb, line 240
    def grayscale_entry(bit_depth)
      value = ChunkyPNG::Canvas.send(:"decode_png_resample_#{bit_depth}bit_value", content.unpack('n')[0])
      ChunkyPNG::Color.grayscale(value)
    end

palette_alpha_channel() click to toggle source

Returns the alpha channel for the palette of an indexed image.

This method should only be used for images having color mode ChunkyPNG::COLOR_INDEXED (3).

@return [Array<Integer>] Returns an array of alpha channel values

    [0-255].

    # File lib/chunky_png/chunk.rb, line 216
    def palette_alpha_channel
      content.unpack('C*')
    end

truecolor_entry(bit_depth) click to toggle source

Returns the truecolor entry to be replaced by transparent pixels,

This method should only be used for images having color mode ChunkyPNG::COLOR_TRUECOLOR (2).

@return [Integer] The color to replace with fully transparent pixels.

    # File lib/chunky_png/chunk.rb, line 226
    def truecolor_entry(bit_depth)
      values = content.unpack('nnn').map do |c|
        ChunkyPNG::Canvas.send(:"decode_png_resample_#{bit_depth}bit_value", c)
      end
      ChunkyPNG::Color.rgb(*values)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.