imaginizer 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fee99c35bfde210d37239c941457949cb2cb24b4
4
- data.tar.gz: bb7031eadd8e90a375ec200e5fbc8cd7bc2cf025
3
+ metadata.gz: e1849cb4371d1e8685c277287ea67ba389615f79
4
+ data.tar.gz: ece5229261b2d160cbd55b81017c06ec922a5ed8
5
5
  SHA512:
6
- metadata.gz: b136a036a217039b2410e851bdf8cbdf02c442051fbcd66795e7f9e3de60a83209b8cec4026dedb85663ae2ed5f5398c517bdbf4e9397315f0db9d8f14098410
7
- data.tar.gz: 83ca37e1b2a61f82133c6e918e79f017206a40f2ac9a44fc68609d4b1c52df438e5c3cf25841ed4f343c66bf641cfa9140a731dd7e7613c4a47ea25c45aa1ca0
6
+ metadata.gz: daff82417025e3978e6fa5b21ab5c3d0e5dded9629d0586ba5242f229cb4ec65167f1842fa961c5f6d0e44f1342cf346fd33ad0aacbada4c74fbcfec8afffb17
7
+ data.tar.gz: b319a690fffa2bd8f18043a18a3037bd060a7e8e6e48d1bbfaa80b74426eb824e382a312c1ba02631369175e2a543df832c909180ff77aad3d1a7c4b50a9db7a
@@ -7,11 +7,14 @@ rescue LoadError
7
7
  require 'imaginizer'
8
8
  end
9
9
 
10
+ require 'imaginizer/image'
10
11
  require 'imaginizer/parser'
11
12
 
12
- options = Imaginizer::Parser.parse ARGV
13
+ sizes, options = Imaginizer::Parser.parse ARGV
13
14
  output = options.delete :output
14
15
  puts "Creating images with #{options}:"
15
- images = Imaginizer.create_images options
16
- puts "Images created at #{images.map &:image_path}"
17
- Imaginizer::Parser.output images, output
16
+ Imaginizer.create_images sizes, options do |images|
17
+ puts "Images created at #{images.values}"
18
+ Imaginizer::Parser.output images, output
19
+ sleep 1 # let the browser open before /tmp images are deleted
20
+ end
@@ -1,24 +1,38 @@
1
- require 'imaginizer/image'
2
-
3
1
  module Imaginizer
4
- def self.create_images(options = {})
5
- sizes = options.delete(:sizes) { [] }
6
- sizes.map {|size| create_image size, options}
2
+ def self.create_images(sizes = [], options = {})
3
+ images = {}
4
+ sizes.each do |size|
5
+ images[size] = create_image size, options
6
+ end
7
+ if block_given?
8
+ yield images
9
+ delete_images images
10
+ else
11
+ images
12
+ end
7
13
  end
8
14
 
9
15
  def self.create_image(size, options = {})
10
- Image.create size, image_path(size) do |image|
11
- image.make_jpeg
12
- image.resize
13
- image.set_background options[:background] if options[:background]
14
- image.set_foreground options[:foreground] if options[:foreground]
15
- image.set_title options[:title] if options[:title]
16
- image.set_subtitle options[:subtitle] if options[:subtitle]
17
- image.set_footer options[:footer] if options[:footer]
16
+ image_path(size).tap do |path|
17
+ Image.create size, path do |image|
18
+ image.make_jpeg
19
+ image.resize
20
+ image.set_background options[:background] if options[:background]
21
+ image.set_foreground options[:foreground] if options[:foreground]
22
+ image.set_title options[:title] if options[:title]
23
+ image.set_subtitle options[:subtitle] if options[:subtitle]
24
+ image.set_footer options[:footer] if options[:footer]
25
+ end
18
26
  end
19
27
  end
20
28
 
29
+ def self.delete_images(images)
30
+ images.values.each{|file| File.delete file}
31
+ end
32
+
21
33
  def self.image_path(size)
22
34
  "/tmp/#{size}.jpg"
23
35
  end
24
- end
36
+ end
37
+
38
+ require 'imaginizer/image'
@@ -2,12 +2,24 @@
2
2
  require 'optparse'
3
3
 
4
4
  class Imaginizer::Parser
5
+ def self.default_options
6
+ {}.tap do |opts|
7
+ opts[:output] = :html
8
+ opts[:title] = 'Title max 18 chars'
9
+ opts[:subtitle] = 'This subtitle is 30 characters'
10
+ opts[:footer] = 'A footer w/ 20 chars'
11
+ opts[:background] = 'http://lorempixel.com/300/300/abstract'
12
+ opts[:foreground] = 'http://lorempixel.com/300/300/people'
13
+ end
14
+ end
15
+
5
16
  def self.valid_sizes
6
17
  [:medium_rectangle, :rectangle, :wide_skyscraper, :leaderboard]
7
18
  end
8
19
 
9
20
  def self.parse(args)
10
- options = default_values
21
+ options = default_options
22
+ sizes = []
11
23
 
12
24
  opt_parser = OptionParser.new do |opts|
13
25
  opts.banner = "Usage: #{File.basename($0)}"
@@ -17,7 +29,7 @@ class Imaginizer::Parser
17
29
 
18
30
  opts.on('-d', '--dimension [IAB_SIZE]', valid_sizes,
19
31
  %Q(Sizes to create #{valid_sizes} – multiple values accepted)) do |d|
20
- options[:sizes] << d
32
+ sizes << d
21
33
  end
22
34
 
23
35
  opts.on('-b', '--background path_or_url', String,
@@ -66,20 +78,8 @@ class Imaginizer::Parser
66
78
 
67
79
  opt_parser.parse!(args)
68
80
 
69
- options[:sizes] = self.valid_sizes if options[:sizes].empty?
70
- options
71
- end
72
-
73
- def self.default_values
74
- {}.tap do |opts|
75
- opts[:output] = :html
76
- opts[:sizes] = []
77
- opts[:title] = 'Title max 18 chars'
78
- opts[:subtitle] = 'This subtitle is 30 characters'
79
- opts[:footer] = 'A footer w/ 20 chars'
80
- opts[:background] = 'http://lorempixel.com/300/300/abstract'
81
- opts[:foreground] = 'http://lorempixel.com/300/300/people'
82
- end
81
+ sizes = valid_sizes if sizes.empty?
82
+ [sizes, options]
83
83
  end
84
84
 
85
85
  def self.output(images, output)
@@ -92,22 +92,22 @@ class Imaginizer::Parser
92
92
  f.write <<-HTML
93
93
  <!DOCTYPE html>
94
94
  <html>
95
- <head>
96
- <meta charset="UTF-8" />
97
- <style>
98
- body {background-color: #ccc}
99
- figure {float: left}
100
- </style>
101
- <title>Imaginizer output</title>
102
- </head>
103
- <body>
104
- #{images.map do |image|
105
- '<figure>' +
106
- '<img src="' + image.image_path + '" />' +
107
- '<figcaption>Size: ' + image.image_size.to_s + '</figcaption>' +
108
- '</figure>'
109
- end.join}
110
- </body>
95
+ <head>
96
+ <meta charset="UTF-8" />
97
+ <style>
98
+ body {background-color: #ccc}
99
+ figure {float: left}
100
+ </style>
101
+ <title>Imaginizer output</title>
102
+ </head>
103
+ <body>
104
+ #{images.map do |size, path|
105
+ '<figure>' +
106
+ '<img src="' + path + '" />' +
107
+ '<figcaption>Size: ' + size.to_s + '</figcaption>' +
108
+ '</figure>'
109
+ end.join}
110
+ </body>
111
111
  </html>
112
112
  HTML
113
113
  end
@@ -1,3 +1,3 @@
1
1
  module Imaginizer
2
- VERSION = '0.0.5'
2
+ VERSION = '0.0.6'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imaginizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claudio Baccigalupo