Class: Pangrid::PNGThumbnail

Inherits:
Plugin
  • Object
show all
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 Method Summary collapse

Methods inherited from Plugin

class_to_name, get, inherited, list_all, load_all, load_plugin

Methods included from PluginUtils

#check

Instance Method Details

#write(xw) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/pangrid/plugins/png.rb', line 7

def write(xw)
  black = ChunkyPNG::Color::BLACK
  white = ChunkyPNG::Color::WHITE
  red = ChunkyPNG::Color::rgb(255, 0, 0)
  grey = ChunkyPNG::Color::rgb(128, 128, 128)
  scale = 4
  png = ChunkyPNG::Image.new(64, 64, 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
  png.rect(0, 0, xw.width * scale, xw.height * scale, stroke_color = red)
  png.to_blob  
end