Method: Pixelart::Pixelator#initialize

Defined in:
lib/pixelart/pixelator.rb

#initialize(img, width = 24, height = 24) ⇒ Pixelator

Returns a new instance of Pixelator.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/pixelart/pixelator.rb', line 6

def initialize( img, width=24, height=24 )
  @img    = img.is_a?( Image ) ? img.image : img  ## "unwrap" if Pixelart::Image
  @width  = width
  @height = height

  ## calculate pixel size / density / resolution
  ##   how many pixels per pixel?
  @xsize, @xoverflow = img.width.divmod( width )
  @ysize, @yoverflow = img.height.divmod( height )

  puts "minify image size from (#{@img.width}x#{@img.height}) to (#{width}x#{height})"
  puts "  pixel size (#{@xsize}x#{@ysize}) - #{@xsize*@ysize} pixel(s) per pixel"
  puts "    overflow x: #{@xoverflow}, y: #{@yoverflow} pixel(s)"    if @xoverflow > 0 || @yoverflow > 0
end