Class: HTMLRender::Images::PNGImage

Inherits:
Base
  • Object
show all
Defined in:
lib/html_render/images.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#==

Constructor Details

#initialize(data) ⇒ PNGImage

Returns a new instance of PNGImage.



21
22
23
# File 'lib/html_render/images.rb', line 21

def initialize(data)
  @png = Magick::Image.from_blob(data)[0]
end

Instance Attribute Details

#pngObject (readonly)

Returns the value of attribute png.



19
20
21
# File 'lib/html_render/images.rb', line 19

def png
  @png
end

Instance Method Details

#<=>(other) ⇒ Object



25
26
27
28
# File 'lib/html_render/images.rb', line 25

def <=>(other)
  self.class.name <=> other.class.name unless PNGImage === other
  png <=> other.png
end

#difference(other) ⇒ Object

Raises:

  • (NotImplementedError)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/html_render/images.rb', line 30

def difference(other)
  raise NotImplementedError unless PNGImage === other

  rows = [ png.rows, other.png.rows ].max
  columns = [ png.columns, other.png.columns ].max

  image = Magick::Image.new(columns, rows) do |info|
    info.format = 'png'
  end
  image.background_color = 'black'
  image.composite!(png, 0, 0, Magick::OverCompositeOp)
  image.composite!(other.png, 0, 0, Magick::DifferenceCompositeOp)
end

#to_blobObject



44
45
46
# File 'lib/html_render/images.rb', line 44

def to_blob
  png.to_blob
end