Class: PalletePNG::Image

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

Constant Summary collapse

NotPNG =
Class.new StandardError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_data) ⇒ Image

Returns a new instance of Image.

Parameters:

  • image_data (String)

    The PNG image data

Raises:

  • (ChunkyPNG::SignatureMismatch)

    if image_data is not a PNG image



12
13
14
# File 'lib/pallete_png/image.rb', line 12

def initialize(image_data)
  @image = ChunkyPNG::Image.from_blob(image_data)
end

Instance Attribute Details

#imageChunkyPNG::Image (readonly)

Returns:

  • (ChunkyPNG::Image)


8
9
10
# File 'lib/pallete_png/image.rb', line 8

def image
  @image
end

Instance Method Details

#datastreamChunkyPNG::Datastream

Returns:

  • (ChunkyPNG::Datastream)


31
32
33
# File 'lib/pallete_png/image.rb', line 31

def datastream
  @datastream ||= image.to_datastream
end

#pallete_based?Boolean

Returns:

  • (Boolean)


21
22
23
24
# File 'lib/pallete_png/image.rb', line 21

def pallete_based?
  color_mode, _depth = image.palette.best_color_settings
  color_mode == ChunkyPNG::COLOR_INDEXED
end

#to_truecolor_alphaString

Returns The new image data that the color_mode is converted to TRUE COLOR alpha.

Returns:

  • (String)

    The new image data that the color_mode is converted to TRUE COLOR alpha



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

def to_truecolor_alpha
  image.to_blob color_mode: ChunkyPNG::COLOR_TRUECOLOR_ALPHA
end

#transparency_chunk?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/pallete_png/image.rb', line 26

def transparency_chunk?
  !datastream.transparency_chunk.nil?
end