Last active
February 21, 2024 22:22
-
-
Save codecaffeine/10292934 to your computer and use it in GitHub Desktop.
Random Image Generator (imagemagick + ruby)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.banner = "Usage: randimg [options] [filename1] [filename2] ..." | |
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]} 'file #{i}.png'` | |
end | |
else | |
files = (!ARGV.empty? && ARGV) || ["random.png"] | |
files.each do |f| | |
`convert -size #{options[:size]} #{options[:type]} #{f}` | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the script! Good work. One thought is to replace space to underscore in file name (line 40). It will be easier to use generated files on the web.