imgen 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f07c448ea4a58966a5f72b95db5b578078a2cbc9
4
+ data.tar.gz: 9e08b079e25b55b303e3dcccf2b488537e32787a
5
+ SHA512:
6
+ metadata.gz: b7cfc5b3dd668ae3ecb431e40c9215a1c225e2c19c6baf45bbffe45c481cf317f5dffcc811f99b4b73371329610d5453de9bbadb34793cf5fe04039f397bec66
7
+ data.tar.gz: 692ef3fde9a6b0607a2cba8327d4381bca4e778b677617bd63a9b1be3a6e8b97591ab7196011f207f67150759ba0a1a9b68249f6dec8fc2441f00e095e04fb14
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /img/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in imgen.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Michael Chadwick
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Imgen
2
+
3
+ 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
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'imgen'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install imgen
20
+
21
+ ## Usage
22
+
23
+ By default, simply running `imgen` will create a single 100x100 PNG, using one of three randomly-selected dominant colors (R, G, or B).
24
+
25
+ It will look something like the following:
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)
30
+
31
+ ![Imgen default blue](https://github.com/michaelchadwick/imgen/blob/master/imgen-example-blue.png)
32
+
33
+ You can change width, height, image format, and the quantity of images generated with switches.
34
+
35
+ `imgen -w 200 -h 300 -f jpg -q 10` - Create 10 200x300 JPGs of random dominant-colored noise.
36
+
37
+ ## Contributing
38
+
39
+ Bug reports and pull requests are welcome on GitHub at https://github.com/michaelchadwick/imgen.
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ require_relative '../lib/imgen'
6
+ require_relative '../lib/imgen/version'
7
+
8
+ BINARY_NAME = $PROGRAM_NAME.split('/').last
9
+
10
+ def parse_options
11
+ options = {
12
+ :width => 100,
13
+ :height => 100,
14
+ :directory => 'img',
15
+ :format => 'png',
16
+ :quantity => 1,
17
+ :display => false
18
+ }
19
+
20
+ optparse = OptionParser.new do |opts|
21
+ 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"
23
+
24
+ opts.on('-w', '--width WIDTH_OF_IMAGE', Integer, 'Width of image in pixels (Default: 100)') do |w|
25
+ options[:width] = w.to_i
26
+ end
27
+
28
+ opts.on('-h', '--height HEIGHT_OF_IMAGE', Integer, 'Height of image in pixels (Default: 100)') do |h|
29
+ options[:height] = h.to_i
30
+ end
31
+
32
+ opts.on('-d', '--directory IMG_DIRECTORY', 'Subdirectory to put generated images (Default: ./img)') do |d|
33
+ options[:directory] = d
34
+ end
35
+
36
+ opts.on('-f', '--format IMG_FORMAT', [:bmp, :gif, :jpg, :png], 'Image format (bmp|gif|jpg|png) (Default: png)') do |f|
37
+ options[:format] = f
38
+ end
39
+
40
+ opts.on('-q', '--quantity QUANTITY', 'Number of images to create (Default: 1)') do |q|
41
+ options[:quantity] = q.to_i
42
+ end
43
+
44
+ opts.on('--display', 'Display image using X11 after creation') do |bg|
45
+ options[:display] = true
46
+ end
47
+
48
+ opts.on('-v', '--version', 'Display version number and exit') do
49
+ puts "#{BINARY_NAME} #{Imgen::VERSION}"
50
+ exit
51
+ end
52
+
53
+ opts.on('--help', 'Display this screen and exit') do
54
+ puts opts
55
+ exit
56
+ end
57
+ end
58
+
59
+ options[:usage] = optparse.to_s
60
+ optparse.parse!()
61
+
62
+ return options
63
+ end
64
+
65
+ def print_error(error)
66
+ case error
67
+ when OptionParser::InvalidOption
68
+ puts "#{BINARY_NAME}: illegal option #{error.args.join(' ')}"
69
+ else
70
+ puts "An unexpected error occurred while running #{BINARY_NAME}:"
71
+ puts " #{error}\n"
72
+ end
73
+ end
74
+
75
+ begin
76
+ options = parse_options
77
+
78
+ Imgen::Image.new(options)
79
+ rescue => error
80
+ print_error(error)
81
+ exit(false)
82
+ end
Binary file
Binary file
Binary file
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'imgen/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "imgen"
8
+ spec.version = Imgen::VERSION
9
+ spec.authors = ["Michael Chadwick"]
10
+ spec.email = ["michael.chadwick@gmail.com"]
11
+ spec.homepage = 'http://rubygems.org/gems/imgen'
12
+ spec.summary = 'Create images from scratch'
13
+ spec.description = 'Create an image of a specific height and width using Magick'
14
+
15
+ spec.files = `git ls-files`.split("\n")
16
+ spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ spec.require_paths = ['lib']
19
+ spec.license = 'MIT'
20
+
21
+ spec.add_runtime_dependency "rmagick"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "pry"
27
+ end
@@ -0,0 +1,58 @@
1
+ require 'rmagick'
2
+ require 'fileutils'
3
+
4
+ module Imgen
5
+ class Image
6
+
7
+ # main entry point
8
+ def initialize(options)
9
+ 1.upto(options[:quantity]) do
10
+ img = Magick::Image.new(options[:width], options[:height])
11
+ colors = {r: 0, g: 0, b: 0}
12
+ color_dominant = colors.keys.to_a.sample
13
+ options[:color_dominant] = color_dominant
14
+
15
+ make_image(img, options)
16
+ end
17
+ end
18
+
19
+ # image processing
20
+ def make_image(img, options)
21
+ (0..img.columns).each do |x|
22
+ (0..img.rows).each do |y|
23
+ red = (options[:color_dominant] == :r) ? rand(0..100) : 0
24
+ green = (options[:color_dominant] == :g) ? rand(0..100) : 0
25
+ blue = (options[:color_dominant] == :b) ? rand(0..100) : 0
26
+ alpha = rand(0..100)
27
+ img.pixel_color(x,y,"rgba(#{red}%, #{green}%, #{blue}%, #{alpha}%)")
28
+ end
29
+ end
30
+
31
+ img_dir = options[:directory]
32
+ img_ext = options[:format]
33
+
34
+ unless File.directory?(img_dir)
35
+ FileUtils.mkdir_p(img_dir)
36
+ end
37
+
38
+ counter = 0
39
+ img_uniq = ""
40
+ filename_path = "#{img_dir}/#{options[:width]}x#{options[:height]}#{img_uniq}.#{img_ext}"
41
+
42
+ until !File.exists?(filename_path)
43
+ counter += 1
44
+ img_uniq = "_" + counter.to_s
45
+ filename_path = "#{img_dir}/#{options[:width]}x#{options[:height]}#{img_uniq}.#{img_ext}"
46
+ end
47
+
48
+ puts "writing #{filename_path} to disk"
49
+ img.write(filename_path)
50
+
51
+ if options[:display]
52
+ puts "displaying #{filename_path} in X11..."
53
+ img.display
54
+ end
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Imgen
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Imgen do
4
+ it 'has a version number' do
5
+ expect(Imgen::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'imgen'
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: imgen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Chadwick
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rmagick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Create an image of a specific height and width using Magick
84
+ email:
85
+ - michael.chadwick@gmail.com
86
+ executables:
87
+ - imgen
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/imgen
99
+ - image-example-blue.png
100
+ - image-example-green.png
101
+ - image-example-red.png
102
+ - imgen.gemspec
103
+ - lib/imgen.rb
104
+ - lib/imgen/version.rb
105
+ - spec/imgen_spec.rb
106
+ - spec/spec_helper.rb
107
+ homepage: http://rubygems.org/gems/imgen
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.6.6
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Create images from scratch
131
+ test_files:
132
+ - spec/imgen_spec.rb
133
+ - spec/spec_helper.rb