Class: Pangrid::PNGThumbnail
- Defined in:
- lib/pangrid/plugins/png.rb
Constant Summary
Constants inherited from Plugin
Pangrid::Plugin::DESCRIPTION, Pangrid::Plugin::FAILED, Pangrid::Plugin::MISSING_DEPS, Pangrid::Plugin::REGISTRY
Instance Attribute Summary collapse
-
#border ⇒ Object
readonly
Returns the value of attribute border.
-
#scale ⇒ Object
readonly
Returns the value of attribute scale.
Instance Method Summary collapse
-
#initialize(scale = 4, border = [128, 0, 0]) ⇒ PNGThumbnail
constructor
A new instance of PNGThumbnail.
- #write(xw) ⇒ Object
Methods inherited from Plugin
class_to_name, get, inherited, list_all, load_all, load_plugin
Methods included from PluginUtils
Constructor Details
#initialize(scale = 4, border = [128, 0, 0]) ⇒ PNGThumbnail
Returns a new instance of PNGThumbnail.
8 9 10 11 |
# File 'lib/pangrid/plugins/png.rb', line 8 def initialize(scale = 4, border = [128, 0, 0]) @scale = scale @border = border end |
Instance Attribute Details
#border ⇒ Object (readonly)
Returns the value of attribute border.
6 7 8 |
# File 'lib/pangrid/plugins/png.rb', line 6 def border @border end |
#scale ⇒ Object (readonly)
Returns the value of attribute scale.
6 7 8 |
# File 'lib/pangrid/plugins/png.rb', line 6 def scale @scale end |
Instance Method Details
#write(xw) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/pangrid/plugins/png.rb', line 13 def write(xw) black = ChunkyPNG::Color::BLACK white = ChunkyPNG::Color::WHITE grey = ChunkyPNG::Color::rgb(128, 128, 128) xdim = xw.width * scale + 2 ydim = xw.height * scale + 2 png = ChunkyPNG::Image.new(xdim, ydim, ChunkyPNG::Color::TRANSPARENT) xw.each_cell_with_coords do |x, y, cell| c = cell.black? ? black : white png.rect( x * scale, y * scale, (x + 1) * scale, (y + 1) * scale, stroke_color = grey, fill_color = c) end if border stroke = ChunkyPNG::Color::rgb(*border) png.rect(0, 0, xw.width * scale, xw.height * scale, stroke_color = stroke) end png.to_blob end |