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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'lib/originals/tool.rb', line 7
def self.main( args=ARGV )
puts "==> welcome to the fab(ricate) tool with args:"
pp args
options = { }
parser = OptionParser.new do |opts|
opts.on("--zoom NUM", "-z", Integer,
"Zoom factor x2, x4, x8, etc. (default: 1)") do |num|
options[ :zoom] = num
end
opts.on("--background STRING", "--bg STRING", "-b", String,
"Background (default: transparent|0x0)") do |str|
options[ :background] = str
end
opts.on("--name STRING", "-n", String,
"Base name (default: punk|phunk|marilyn|etc.)") do |str|
options[ :name] = str
end
opts.on("--id NUM", "-i", Integer,
"Unique identifier (default: none)") do |str|
options[ :id] = str
end
opts.on( "--require STRING", "-r", String, "Require image library / gem (default: none)") do |str|
options[ :gems ] = str
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end
parser.parse!( args )
puts "options:"
pp options
puts "args:"
pp args
if args.size < 1
puts "!! ERROR - no art series name found - use <name> <attribute>..."
puts ""
exit
end
if options[:gems]
gems = options[:gems].split(',')
gems.each do |gem|
puts "==> auto-require >#{gem}<..."
require gem
end
end
name = args[0]
if ['ls', 'list'].include?( name )
Original.factory.list
exit
end
attributes = args[1..-1]
key = Factory.normalize_key( name )
id = nil
img = if attributes.size == 1 && id=_parse_id( attributes[0] )
if ['phunk', 'phunks'].include?( key )
Artbase::Image.get( 'punks', id ).mirror
elsif ['morephunk', 'morephunks'].include?( key )
Artbase::Image.get( 'morepunks', id ).mirror
elsif ['bwphunk', 'bwphunks'].include?( key )
Artbase::Image.get( 'bwpunks', id ).mirror
elsif ['readymadephunk', 'readymadephunks'].include?( key )
Artbase::Image.get( 'readymadepunks', id ).mirror
elsif ['intlphunk', 'intlphunks'].include?( key )
Artbase::Image.get( 'intlpunks', id ).mirror
elsif ['phoonbird', 'phoonbirds',
'moonbhird', 'moonbhirds',
'bhird', 'bhirds'].include?( key )
Artbase::Image.get( 'moonbirds', id ).mirror
elsif ['moonbirdphunk', 'moonbirdphunks',
'birdphunk', 'birdphunks'].include?( key )
Artbase::Image.get( 'moonbirdpunks', id ).mirror
else
collection = Artbase::COLLECTIONS[ key ] || key
Artbase::Image.get( collection, id )
end
else
Original::Image.fabricate( key, *attributes )
end
if img.nil?
puts "!! ERROR - don't know how to fabricate >#{name}<; sorry"
exit 1
end
if options[ :background]
img = img.transparent if id
backgrounds = options[ :background].split( '+' )
backgrounds = backgrounds.map {|background| background.strip }
img = img.background( *backgrounds )
end
basename = String.new('') basename += options[:name] ? options[:name] : key
basename += if options[:id]
options[:id]
elsif id
id.to_s
else
'' end
path = if options[:zoom]
img = img.zoom( options[:zoom] )
"./#{basename}@#{options[:zoom]}x.png"
else
"./#{basename}.png"
end
puts " saving original #{name} (#{img.width}x#{img.height}) to >#{path}<..."
img.save( path )
puts "bye"
end
|