Class: Cryptopunks::Image::Composite

Inherits:
Object
  • Object
show all
Defined in:
lib/cryptopunks/composite.rb

Overview

nest Composite inside Image - why? why not?

Constant Summary collapse

PUNK_ROWS =
100
PUNK_COLS =
100
PUNK_COUNT =

10_000 = 100x100 (24000x24000 pixel)

PUNK_ROWS * PUNK_COLS
PUNK_HEIGHT =
24
PUNK_WIDTH =
24
PUNK_HASH =
'ac39af4793119ee46bbff351d8cb6b5f23da60222126add4268e261199a2921b'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data) ⇒ Composite

Returns a new instance of Composite.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cryptopunks/composite.rb', line 22

def initialize( data )
  @punks = ChunkyPNG::Image.from_blob( data )
  puts "     #{@punks.height}x#{@punks.width} (height x width)"

  ## check sha256 checksum
  @hexdigest = sha256( data )
  if original?
     puts "     >#{@hexdigest}< SHA256 hash matching"
     puts "         ✓ True Official Genuine CryptoPunks™ verified"
  else
     puts " !! ERROR: >#{hexdigest}< SHA256 hash NOT matching"
     puts "           >#{PUNK_HASH}< expected for True Official Genuine CryptoPunks™."
     puts ""
     puts "     Sorry, please download the original."
     exit 1
  end
end

Class Method Details

.read(path = './punks.png') ⇒ Object



6
7
8
9
# File 'lib/cryptopunks/composite.rb', line 6

def self.read( path='./punks.png' )
  data = File.open( path, 'rb' ) { |f| f.read }
  new( data )
end

Instance Method Details

#hexdigestObject



47
# File 'lib/cryptopunks/composite.rb', line 47

def hexdigest()  @hexdigest end

#punk(index) ⇒ Object Also known as: []



58
59
60
61
62
# File 'lib/cryptopunks/composite.rb', line 58

def punk( index )
  y, x = index.divmod( PUNK_ROWS )
  img = @punks.crop( x*PUNK_WIDTH, y*PUNK_HEIGHT, PUNK_WIDTH, PUNK_HEIGHT )
  Pixelart::Image.new( img.width, img.height, img )  ## wrap in pixelart image
end

#sha256(data) ⇒ Object



41
42
43
44
# File 'lib/cryptopunks/composite.rb', line 41

def sha256( data )
  ## todo/check: or just use Digest::SHA256.hexdigest - why? why not?
  Digest::SHA256.digest( data ).unpack( 'H*' )[0]
end

#sizeObject



55
# File 'lib/cryptopunks/composite.rb', line 55

def size() PUNK_COUNT; end

#verify?Boolean Also known as: genuine?, original?

Returns:

  • (Boolean)


49
# File 'lib/cryptopunks/composite.rb', line 49

def verify?()  @hexdigest == PUNK_HASH; end