imgen 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -6
- data/bin/imgen +11 -1
- data/lib/imgen.rb +43 -8
- data/lib/imgen/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff5cd4c4bb09e88abc71981897fe8ac541f1f29e
|
4
|
+
data.tar.gz: 0a4b3745b1c32f6154b4e790092ae70d3fa691c2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31fc05912932708ffa9524bc2f50af3605a9f80bec59c97ed0f04b4e3eb74a130200bc4913e9ae517b819bae9e2ef4d98310969d634c3dd5cff129b82e32fc97
|
7
|
+
data.tar.gz: 415b78a79be7df09f06f2fbcf6acb9f00c8dd9adea0978789c0acb35f1e8c0e520c75a91497f88ea70c74e303c490ee9e1407d334d5de17cdec9a588c47da6ce
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Imgen
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/imgen.svg)](https://badge.fury.io/rb/imgen)
|
4
|
+
|
3
5
|
Imgen is a quick and simple way to create simple, placeholder-type images. One line can make 1, 5, or 100 PNGs, perfect for testing out any project that needs imagery.
|
4
6
|
|
5
7
|
## Installation
|
@@ -22,13 +24,9 @@ Or install it yourself as:
|
|
22
24
|
|
23
25
|
By default, simply running `imgen` will create a single 100x100 PNG, using one of three randomly-selected dominant colors (R, G, or B).
|
24
26
|
|
25
|
-
|
26
|
-
|
27
|
-
![Imgen default red](https://github.com/michaelchadwick/imgen/blob/master/imgen-example-red.png)
|
28
|
-
|
29
|
-
![Imgen default green](https://github.com/michaelchadwick/imgen/blob/master/imgen-example-green.png)
|
27
|
+
The resulting image will look something like one of the following:
|
30
28
|
|
31
|
-
![Imgen default
|
29
|
+
![Imgen default red](https://github.com/michaelchadwick/imgen/blob/master/image-example-red.png) ![Imgen default green](https://github.com/michaelchadwick/imgen/blob/master/image-example-green.png) ![Imgen default blue](https://github.com/michaelchadwick/imgen/blob/master/image-example-blue.png)
|
32
30
|
|
33
31
|
You can change width, height, image format, and the quantity of images generated with switches.
|
34
32
|
|
data/bin/imgen
CHANGED
@@ -14,12 +14,14 @@ def parse_options
|
|
14
14
|
:directory => 'img',
|
15
15
|
:format => 'png',
|
16
16
|
:quantity => 1,
|
17
|
+
:method => :noise,
|
18
|
+
:debug => false,
|
17
19
|
:display => false
|
18
20
|
}
|
19
21
|
|
20
22
|
optparse = OptionParser.new do |opts|
|
21
23
|
opts.banner = "Generate images on the command line\n"
|
22
|
-
opts.banner += "usage: imgen [-w, --width WIDTH] [-h, --height HEIGHT] [-d, --directory IMG_DIRECTORY] [-f, --format IMG_FORMAT] [-q, --quantity QUANTITY] [--display]\n\n"
|
24
|
+
opts.banner += "usage: imgen [-w, --width WIDTH] [-h, --height HEIGHT] [-d, --directory IMG_DIRECTORY] [-f, --format IMG_FORMAT] [-q, --quantity QUANTITY] [-m, --method GEN_METHOD] [--debug] [--display]\n\n"
|
23
25
|
|
24
26
|
opts.on('-w', '--width WIDTH_OF_IMAGE', Integer, 'Width of image in pixels (Default: 100)') do |w|
|
25
27
|
options[:width] = w.to_i
|
@@ -41,6 +43,14 @@ def parse_options
|
|
41
43
|
options[:quantity] = q.to_i
|
42
44
|
end
|
43
45
|
|
46
|
+
opts.on('-m', '--method METHOD', [:noise, :lines], 'Image generation method (Default: noise)') do |m|
|
47
|
+
options[:method] = m
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on('--debug', 'Display pixel debug information') do |debug|
|
51
|
+
options[:debug] = true
|
52
|
+
end
|
53
|
+
|
44
54
|
opts.on('--display', 'Display image using X11 after creation') do |bg|
|
45
55
|
options[:display] = true
|
46
56
|
end
|
data/lib/imgen.rb
CHANGED
@@ -18,14 +18,45 @@ module Imgen
|
|
18
18
|
|
19
19
|
# image processing
|
20
20
|
def make_image(img, options)
|
21
|
+
last_pixel = {}
|
22
|
+
new_pixel = {}
|
23
|
+
|
21
24
|
(0..img.columns).each do |x|
|
22
25
|
(0..img.rows).each do |y|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
26
|
+
case options[:method]
|
27
|
+
when :lines
|
28
|
+
if !last_pixel.empty?
|
29
|
+
if last_pixel[:color_dominant] == 100
|
30
|
+
new_pixel[options[:color_dominant]] = 0
|
31
|
+
elsif last_pixel[:color_dominant] == 0
|
32
|
+
new_pixel[options[:color_dominant]] = rand(1..10) + last_pixel[options[:color_dominant]]
|
33
|
+
else
|
34
|
+
new_pixel[options[:color_dominant]] = rand(-10..10) + last_pixel[options[:color_dominant]]
|
35
|
+
end
|
36
|
+
else
|
37
|
+
new_pixel[:r] = (options[:color_dominant] == :r) ? rand(0..100) : 0
|
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)
|
41
|
+
end
|
42
|
+
when :noise
|
43
|
+
new_pixel[:r] = (options[:color_dominant] == :r) ? rand(0..100) : 0
|
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)
|
47
|
+
end
|
48
|
+
|
49
|
+
img.pixel_color(x,y,"rgba(#{new_pixel[:r]}%, #{new_pixel[:g]}%, #{new_pixel[:b]}%, #{new_pixel[:a]}%)")
|
50
|
+
last_pixel = {r: new_pixel[:r], g: new_pixel[:g], b: new_pixel[:b], a: new_pixel[:a]}
|
51
|
+
|
52
|
+
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)}| "
|
57
|
+
end
|
28
58
|
end
|
59
|
+
print "\n" if options[:debug]
|
29
60
|
end
|
30
61
|
|
31
62
|
img_dir = options[:directory]
|
@@ -36,7 +67,7 @@ module Imgen
|
|
36
67
|
end
|
37
68
|
|
38
69
|
counter = 0
|
39
|
-
img_uniq = ""
|
70
|
+
img_uniq = "_0"
|
40
71
|
filename_path = "#{img_dir}/#{options[:width]}x#{options[:height]}#{img_uniq}.#{img_ext}"
|
41
72
|
|
42
73
|
until !File.exists?(filename_path)
|
@@ -49,8 +80,12 @@ module Imgen
|
|
49
80
|
img.write(filename_path)
|
50
81
|
|
51
82
|
if options[:display]
|
52
|
-
|
53
|
-
|
83
|
+
begin
|
84
|
+
puts "displaying #{filename_path} in X11..."
|
85
|
+
img.display
|
86
|
+
rescue
|
87
|
+
puts "could not display #{filename_path}"
|
88
|
+
end
|
54
89
|
end
|
55
90
|
end
|
56
91
|
|
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.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Chadwick
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
version: '0'
|
125
125
|
requirements: []
|
126
126
|
rubyforge_project:
|
127
|
-
rubygems_version: 2.6.
|
127
|
+
rubygems_version: 2.6.7
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Create images from scratch
|