-
Notifications
You must be signed in to change notification settings - Fork 0
/
random_image.rb
45 lines (35 loc) · 1.04 KB
/
random_image.rb
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
#!/usr/bin/env ruby
# Script to generate random images. Based on http://www.imagemagick.org/Usage/canvas/#random_blur
require 'optparse'
options = {}
optparse = OptionParser.new do |opts|
opts.on( '-s', '--size HxV', 'create image of size HxV (400x400 default)' ) do |size|
options[:size] = size
end
options[:size] ||= "400x400"
opts.on( '-t', '--type TYPE', 'random generator type (noise|plasma)' ) do |size|
case size
when 'plasma'
options[:type] = "plasma:"
end
end
options[:type] ||= "xc: +noise Random"
opts.on( '-n', '--number NUMBER', 'number of files to create (ignores filenames)' ) do |number|
options[:number] = number.to_i
end
opts.on( '-h', '--help', 'Display this screen' ) do
puts opts
exit
end
end
optparse.parse!
if options[:number]
for i in 1..options[:number]
`convert -size #{options[:size]} #{options[:type]} '#{i}.png'`
end
else
files = (!ARGV.empty? && ARGV) || ["random.png"]
files.each do |f|
`convert -size #{options[:size]} #{options[:type]} #{f}`
end
end