imgen 0.1.3 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/imgen +10 -4
- data/lib/imgen.rb +69 -25
- data/lib/imgen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1bcf3df17cdbde3491532b639b733de6d24f5b2f507105dab5e55d46d2e4a059
|
4
|
+
data.tar.gz: f0c1ae27eb1ce10b29ca6a747a4ea66b47414dc16b5c5638261562e84a3d15b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de67ec86dabccbc45d653ca9340f8a9207b28a962839cf3a8077df7fd11d5a1e925c4a521e4215453157dde861ae1cd85bf4d5dbee9b3bc7f273ae271da3632
|
7
|
+
data.tar.gz: 882529c032b94478bcfcbc550dfb86ae7ecb5673a806a07880f81e513f37913a8d465b4b46a401ce85a196942ab4b4a4f7488b59d6d19974dc423ba6f21d273a
|
data/bin/imgen
CHANGED
@@ -15,8 +15,10 @@ def parse_options
|
|
15
15
|
:format => 'png',
|
16
16
|
:quantity => 1,
|
17
17
|
:method => :noise,
|
18
|
+
:filename_path => '',
|
18
19
|
:debug => false,
|
19
|
-
:
|
20
|
+
:display_x11 => false,
|
21
|
+
:display_imgcat => false
|
20
22
|
}
|
21
23
|
|
22
24
|
optparse = OptionParser.new do |opts|
|
@@ -47,12 +49,16 @@ def parse_options
|
|
47
49
|
options[:method] = m
|
48
50
|
end
|
49
51
|
|
50
|
-
opts.on('--debug', 'Display pixel debug information') do
|
52
|
+
opts.on('--debug', 'Display pixel debug information') do
|
51
53
|
options[:debug] = true
|
52
54
|
end
|
53
55
|
|
54
|
-
opts.on('--display', 'Display image using X11 after creation') do
|
55
|
-
options[:
|
56
|
+
opts.on('--display-x11', 'Display image using X11 after creation') do
|
57
|
+
options[:display_x11] = true
|
58
|
+
end
|
59
|
+
|
60
|
+
opts.on('--display-imgcat', 'Display image using imgcat after creation') do
|
61
|
+
options[:display_imgcat] = true
|
56
62
|
end
|
57
63
|
|
58
64
|
opts.on('-v', '--version', 'Display version number and exit') do
|
data/lib/imgen.rb
CHANGED
@@ -3,14 +3,15 @@ require 'fileutils'
|
|
3
3
|
|
4
4
|
module Imgen
|
5
5
|
class Image
|
6
|
+
MAX = Magick::QuantumRange
|
6
7
|
|
7
8
|
# main entry point
|
8
9
|
def initialize(options)
|
9
10
|
1.upto(options[:quantity]) do
|
10
11
|
img = Magick::Image.new(options[:width], options[:height])
|
12
|
+
#img.colorspace = Magick::RGBColorspace
|
11
13
|
colors = {r: 0, g: 0, b: 0}
|
12
|
-
color_dominant = colors.keys.to_a.sample
|
13
|
-
options[:color_dominant] = color_dominant
|
14
|
+
options[:color_dominant] = colors.keys.to_a.sample
|
14
15
|
|
15
16
|
make_image(img, options)
|
16
17
|
end
|
@@ -21,6 +22,7 @@ module Imgen
|
|
21
22
|
last_pixel = {}
|
22
23
|
new_pixel = {}
|
23
24
|
|
25
|
+
# iterate over each pixel
|
24
26
|
(0..img.columns).each do |x|
|
25
27
|
(0..img.rows).each do |y|
|
26
28
|
case options[:method]
|
@@ -34,31 +36,61 @@ module Imgen
|
|
34
36
|
new_pixel[options[:color_dominant]] = rand(-10..10) + last_pixel[options[:color_dominant]]
|
35
37
|
end
|
36
38
|
else
|
37
|
-
new_pixel
|
38
|
-
new_pixel[:g] = (options[:color_dominant] == :g) ? rand(0..100) : 0
|
39
|
-
new_pixel[:b] = (options[:color_dominant] == :b) ? rand(0..100) : 0
|
40
|
-
new_pixel[:a] = rand(0..100)
|
39
|
+
new_pixel = make_new_pixel(options[:color_dominant])
|
41
40
|
end
|
42
41
|
when :noise
|
43
|
-
new_pixel
|
44
|
-
new_pixel[:g] = (options[:color_dominant] == :g) ? rand(0..100) : 0
|
45
|
-
new_pixel[:b] = (options[:color_dominant] == :b) ? rand(0..100) : 0
|
46
|
-
new_pixel[:a] = rand(0..100)
|
42
|
+
new_pixel = make_new_pixel(options[:color_dominant])
|
47
43
|
end
|
48
44
|
|
49
|
-
|
50
|
-
|
45
|
+
pixel = Magick::Pixel.new(
|
46
|
+
new_pixel[:r],
|
47
|
+
new_pixel[:g],
|
48
|
+
new_pixel[:b],
|
49
|
+
new_pixel[:a]
|
50
|
+
)
|
51
|
+
|
52
|
+
# change pixel color
|
53
|
+
img.pixel_color(x, y, pixel)
|
54
|
+
|
55
|
+
# save values of last color change
|
56
|
+
last_pixel = new_pixel
|
51
57
|
|
52
58
|
if options[:debug]
|
53
|
-
print "R#{new_pixel[:r].to_s.ljust(3)}"
|
54
|
-
print "G#{new_pixel[:g].to_s.ljust(3)}"
|
55
|
-
print "B#{new_pixel[:b].to_s.ljust(3)}"
|
56
|
-
print "A#{new_pixel[:a].to_s.ljust(3)}|
|
59
|
+
print "R#{new_pixel[:r].to_s.ljust(3)} "
|
60
|
+
print "G#{new_pixel[:g].to_s.ljust(3)} "
|
61
|
+
print "B#{new_pixel[:b].to_s.ljust(3)} "
|
62
|
+
print "A#{new_pixel[:a].to_s.ljust(3)}|"
|
57
63
|
end
|
58
64
|
end
|
65
|
+
|
59
66
|
print "\n" if options[:debug]
|
60
67
|
end
|
61
68
|
|
69
|
+
write_image_to_file(img, options)
|
70
|
+
|
71
|
+
display_image(img, options)
|
72
|
+
end
|
73
|
+
|
74
|
+
# overwrite pixel with new color
|
75
|
+
def make_new_pixel(color_dominant)
|
76
|
+
clr_strong = rand(0..MAX)
|
77
|
+
|
78
|
+
case color_dominant
|
79
|
+
when :r
|
80
|
+
new_pixel = {:r => clr_strong, :g => clr_strong / 2, :b => clr_strong / 2}
|
81
|
+
when :g
|
82
|
+
new_pixel = {:r => clr_strong / 2, :g => clr_strong, :b => clr_strong / 2}
|
83
|
+
when :b
|
84
|
+
new_pixel = {:r => clr_strong / 2, :g => clr_strong / 2, :b => clr_strong}
|
85
|
+
end
|
86
|
+
|
87
|
+
new_pixel[:a] = rand(0..MAX)
|
88
|
+
|
89
|
+
return new_pixel
|
90
|
+
end
|
91
|
+
|
92
|
+
# write image to disk
|
93
|
+
def write_image_to_file(img, options)
|
62
94
|
img_dir = options[:directory]
|
63
95
|
img_ext = options[:format]
|
64
96
|
|
@@ -68,26 +100,38 @@ module Imgen
|
|
68
100
|
|
69
101
|
counter = 0
|
70
102
|
img_uniq = "_0"
|
71
|
-
filename_path = "#{img_dir}/#{options[:width]}x#{options[:height]}#{img_uniq}.#{img_ext}"
|
103
|
+
options[:filename_path] = "#{img_dir}/#{options[:width]}x#{options[:height]}#{img_uniq}.#{img_ext}"
|
72
104
|
|
73
|
-
until !File.exists?(filename_path)
|
105
|
+
until !File.exists?(options[:filename_path])
|
74
106
|
counter += 1
|
75
107
|
img_uniq = "_" + counter.to_s
|
76
|
-
filename_path = "#{img_dir}/#{options[:width]}x#{options[:height]}#{img_uniq}.#{img_ext}"
|
108
|
+
options[:filename_path] = "#{img_dir}/#{options[:width]}x#{options[:height]}#{img_uniq}.#{img_ext}"
|
77
109
|
end
|
78
110
|
|
79
|
-
puts "writing #{filename_path} to disk"
|
80
|
-
|
111
|
+
puts "writing #{options[:filename_path]} to disk"
|
112
|
+
|
113
|
+
begin
|
114
|
+
img.write(options[:filename_path])
|
115
|
+
rescue
|
116
|
+
puts 'error writing image to disk'
|
117
|
+
end
|
118
|
+
end
|
81
119
|
|
82
|
-
|
120
|
+
# optionally display image after creation
|
121
|
+
def display_image(img, options)
|
122
|
+
if options[:display_x11]
|
83
123
|
begin
|
84
|
-
puts "displaying #{filename_path} in X11..."
|
85
124
|
img.display
|
86
125
|
rescue
|
87
|
-
puts "could not display #{filename_path}"
|
126
|
+
puts "could not display #{options[:filename_path]}"
|
127
|
+
end
|
128
|
+
elsif options[:display_imgcat]
|
129
|
+
begin
|
130
|
+
system("imgcat #{options[:filename_path]}")
|
131
|
+
rescue
|
132
|
+
puts "could not display #{options[:filename_path]}"
|
88
133
|
end
|
89
134
|
end
|
90
135
|
end
|
91
|
-
|
92
136
|
end
|
93
137
|
end
|
data/lib/imgen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: imgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Chadwick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-01-
|
11
|
+
date: 2018-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|