dummyimage 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f6e025ad905a262b627048a9af4a38ac83cb8e5
4
+ data.tar.gz: babcc6323dd7ccaeaa7498704919370dac3efaf4
5
+ SHA512:
6
+ metadata.gz: 5e5fda8b10b6a043956dd65536e1dc05fa73121702416435344aed8f5941275fbd97e46b692cc89b7ab9a538779f44dc246fca22da008a5c01265ca4b79fb814
7
+ data.tar.gz: 0e156a12d3009beadbef28e56f947d77cb7ae2717a3f9af6609134ffcee0003db5e742fbcf56354f3435b6f2be135880504bb02a1791b3fb93d51a96e106aa2d
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../lib/image.rb"
4
+ require "optparse"
5
+
6
+ options = {}
7
+
8
+ optparse = OptionParser.new do |opts|
9
+ opts.banner = "Usage: "
10
+ options[:width] = "400"
11
+ opts.on("-w", "--width WIDTH", "Image width") do |width|
12
+ options[:width] = width
13
+ end
14
+ options[:height] = "300"
15
+ opts.on("-h", "--height HEIGHT", "Image height") do |height|
16
+ options[:height] = height
17
+ end
18
+ options[:fgcolor] = "fff"
19
+ opts.on("-f", "--foreground FOREGROUND", "Image foreground color") do |fg|
20
+ options[:fgcolor] = fg
21
+ end
22
+ options[:bgcolor] = "000"
23
+ opts.on("-b", "--background BACKGROUND", "Image background color") do |bg|
24
+ options[:bgcolor] = bg
25
+ end
26
+ options[:path] = ".png"
27
+ opts.on("-o", "--output PATH", "Image output name") do |path|
28
+ options[:path] = path
29
+ end
30
+
31
+ options[:help] = false
32
+ opts.on("--help", nil, "Display this screen") do
33
+ puts opts
34
+ options[:help] = true
35
+ end
36
+ end
37
+
38
+ optparse.parse!
39
+
40
+ unless options[:help]
41
+ parser = DummyImage::Parser.new options[:path], width: options[:width], height: options[:height], bgcolor: options[:bgcolor], fgcolor: options[:fgcolor]
42
+
43
+ DummyImage::Image.new(parser).image
44
+ system "echo", "-e", "\e[92mYour dummy image is successfully created!"
45
+ end
@@ -0,0 +1,28 @@
1
+ require_relative "./parser.rb"
2
+
3
+ module DummyImage
4
+ class Image
5
+ def initialize parser
6
+ @parser = parser
7
+ end
8
+
9
+
10
+ def image
11
+ unless File.exists? image_name
12
+ create_image!
13
+ end
14
+ image_name
15
+ end
16
+
17
+ private
18
+ def create_image!
19
+ system "convert -size #{@parser.width}x#{@parser.height} -background '##{@parser.bgcolor}' -fill '##{@parser.fgcolor}' -gravity Center +pointsize label:'#{@parser.width}x#{@parser.height}' #{image_name}"
20
+ end
21
+
22
+
23
+ def image_name
24
+ [@parser.width, @parser.height, @parser.bgcolor, @parser.fgcolor, @parser.path].join("_") + "." + @parser.format
25
+ end
26
+ end
27
+ end
28
+
@@ -0,0 +1,45 @@
1
+ module DummyImage
2
+ class Parser
3
+ def initialize path, options = {}
4
+ @path, @format = path.split ".", 2
5
+ @options = options
6
+ end
7
+
8
+ def format
9
+ if %w(png jpg jpeg gif).include? @format
10
+ @format
11
+ else
12
+ "png"
13
+ end
14
+ end
15
+
16
+ def path
17
+ @path
18
+ end
19
+
20
+ def height
21
+ @height ||= valid_size(@options[:height]) || "300"
22
+ end
23
+
24
+ def width
25
+ @width ||= valid_size(@options[:width]) || "300"
26
+ end
27
+
28
+ def fgcolor
29
+ @fgcolor ||= valid_color(@options[:fgcolor]) || "fff"
30
+ end
31
+
32
+ def bgcolor
33
+ @bgcolor ||= valid_color(@options[:bgcolor]) || "000"
34
+ end
35
+
36
+ private
37
+ def valid_size size
38
+ size[/^\d+$/] if size
39
+ end
40
+
41
+ def valid_color color
42
+ color[/^[\da-fA-F]+$/] if color
43
+ end
44
+ end
45
+ end
File without changes
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dummyimage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tran Xuan Nam
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mini_magick
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.5'
27
+ description: A simple gem which will generates a dummy image
28
+ email: tran.xuan.nam@framgia.com
29
+ executables:
30
+ - dummyimage
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - bin/dummyimage
35
+ - lib/image.rb
36
+ - lib/parser.rb
37
+ - lib/version.rb
38
+ homepage: https://rubygems.org/gems/dummyimage
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.5.1
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Dummy Image
62
+ test_files: []