-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathgrayscale.rb
More file actions
88 lines (50 loc) · 1.75 KB
/
Copy pathgrayscale.rb
File metadata and controls
88 lines (50 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
###
# to run use:
# ruby ./grayscale.rb
require 'cryptopunks'
print "==> loading image..."
punks = Punks::Image::Composite.read( '../../programming-cryptopunks/punks.png' )
print "OK\n"
## change all 10 000 punks to grayscale
punks_grayscale = punks.grayscale
punks_grayscale.save( "i/punks_grayscale.png" )
## reload as a composite image (with easy tile access via [])
punks_grayscale = Punks::Image::Composite.read( 'i/punks_grayscale.png' )
punks_grayscale[2243].save( 'i/punk2243_grayscale.png' )
## let's have a looksie at the first five grayscale punks
(0..5).each do |id|
punk = punks_grayscale[id]
punk.save( "i/punk#{id}_grayscale.png" )
punk.zoom(8).save( "i/punk#{id}_grayscalex8.png" )
end
#######
## bonus
## create a 10x10 preview composite
punks_grayscale_preview = ImageComposite.new( 10, 10 )
(0..99).each do |id|
punk = punks_grayscale[id]
punks_grayscale_preview << punk
end
punks_grayscale_preview.save( "i/punks_grayscale_preview.png" )
## Let's try another round with ye olde' sepia vintage colors
## change all 10 000 punks to sepia
punks_sepia = punks.change_palette8bit( Palette8bit::SEPIA )
punks_sepia.save( "i/punks_sepia.png" )
## reload as a composite image (with easy tile access via [])
punks_sepia = Punks::Image::Composite.read( 'i/punks_sepia.png' )
## let's have a looksie at the first five sepia punks
(0..5).each do |id|
punk = punks_sepia[id]
punk.save( "i/punk#{id}_sepia.png" )
punk.zoom(8).save( "i/punk#{id}_sepiax8.png" )
end
#######
## bonus
## create a 10x10 preview composite
punks_sepia_preview = ImageComposite.new( 10, 10 )
(0..99).each do |id|
punk = punks_sepia[id]
punks_sepia_preview << punk
end
punks_sepia_preview.save( "i/punks_sepia_preview.png" )
puts "bye"