Module: PalletePNG

Defined in:
lib/pallete_png.rb,
lib/pallete_png/image.rb,
lib/pallete_png/version.rb

Defined Under Namespace

Classes: Image

Constant Summary collapse

VERSION =
'1.0.1'

Class Method Summary collapse

Class Method Details

.to_transparency(image_data) ⇒ String

Returns The PNG image data.

Examples:

image_data = PalletePNG.to_transparency File.binread('pallete-based-w-transparency.png')

Parameters:

  • image_data (String)

    The PNG image data

Returns:

  • (String)

    The PNG image data

Raises:



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pallete_png.rb', line 10

def self.to_transparency(image_data)
  begin
    image = Image.new image_data
  rescue ChunkyPNG::SignatureMismatch
    raise Image::NotPNG
  end

  # Returns the raw image data if image is not a pallete-based PNG with transparency
  return image_data unless image.pallete_based? && image.transparency_chunk?

  image.to_truecolor_alpha
end