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 +4 -4
- data/bin/imaginizer +7 -4
- data/lib/imaginizer.rb +28 -14
- data/lib/imaginizer/parser.rb +32 -32
- data/lib/imaginizer/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e1849cb4371d1e8685c277287ea67ba389615f79
|
4
|
+
data.tar.gz: ece5229261b2d160cbd55b81017c06ec922a5ed8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: daff82417025e3978e6fa5b21ab5c3d0e5dded9629d0586ba5242f229cb4ec65167f1842fa961c5f6d0e44f1342cf346fd33ad0aacbada4c74fbcfec8afffb17
|
7
|
+
data.tar.gz: b319a690fffa2bd8f18043a18a3037bd060a7e8e6e48d1bbfaa80b74426eb824e382a312c1ba02631369175e2a543df832c909180ff77aad3d1a7c4b50a9db7a
|
data/bin/imaginizer
CHANGED
@@ -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
|
-
|
16
|
-
puts "Images created at #{images.
|
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
|
data/lib/imaginizer.rb
CHANGED
@@ -1,24 +1,38 @@
|
|
1
|
-
require 'imaginizer/image'
|
2
|
-
|
3
1
|
module Imaginizer
|
4
|
-
def self.create_images(options = {})
|
5
|
-
|
6
|
-
sizes.
|
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
|
-
|
11
|
-
image
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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'
|
data/lib/imaginizer/parser.rb
CHANGED
@@ -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 =
|
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
|
-
|
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
|
-
|
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
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
'<figcaption>Size: ' +
|
108
|
-
|
109
|
-
|
110
|
-
|
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
|
data/lib/imaginizer/version.rb
CHANGED