favicon_maker 1.1.2 → 1.2.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eaa73c03522ae6619963ff97c6fef9c05ca16efb
4
- data.tar.gz: 1d3d0730eb5ac9435ea48daf53653997ba3d5eb2
3
+ metadata.gz: a96b698809c2a16905b7b58d0118b5106c4fc39b
4
+ data.tar.gz: 023d995146b9e3f1842b4ab0da7702486397089d
5
5
  SHA512:
6
- metadata.gz: 13ea1e79438db7300be2e2b0815fe002657757316fac34926ed3120fa067bd16f337fe1f54d8ad2ea3c2c55a0d0cd42823820d18749b699b17eadb8872cd557d
7
- data.tar.gz: 25f2cdb5b822cb878589863cfa5ed7da3ccc7db9669374d8d37ac6782cb594507d9a3c5a5434991363b13d9c10f6466b78dbe245ee2dd8f427c35b17ece73d02
6
+ metadata.gz: a0a5f276df6378394239bbd6b55e007a936014a0530eb2db797f9ec48face70ad9dfc280f0eaace01dc0471c93f35ac16985b7fc7ca77c22682893ece16968dc
7
+ data.tar.gz: c988f8e0869737b39a5a909192db88ea94f5f15917a81d030a620547a838d9a1cef5a78e9fbb7f7ea5c9c097ef7d6f62633c61b062c54da95563f1f43f8f63a7
data/.gitignore CHANGED
@@ -4,5 +4,5 @@ Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
6
 
7
- /spec/generated/
8
- .DS_Store
7
+ /spec/output*/
8
+ .DS_Store
@@ -0,0 +1 @@
1
+ 2.1.0
@@ -18,9 +18,8 @@ Gem::Specification.new do |s|
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
- s.add_runtime_dependency("mini_magick", ["~> 3.7"])
22
- s.add_runtime_dependency 'docile', '~> 1.1.3'
21
+ s.add_runtime_dependency 'docile', '~> 1.1'
23
22
 
24
23
  s.add_development_dependency 'rspec', '~> 2.14', '>= 2.14.1'
25
24
  s.add_development_dependency 'guard-rspec', '~> 1.2'
26
- end
25
+ end
@@ -1,4 +1,3 @@
1
- require "mini_magick"
2
1
  require 'fileutils'
3
2
 
4
3
  module FaviconMaker
@@ -9,30 +8,21 @@ module FaviconMaker
9
8
 
10
9
  attr_accessor :template_file_path
11
10
  attr_accessor :output_path
12
- attr_accessor :colorspace_in
13
- attr_accessor :colorspace_out
11
+ attr_accessor :options
14
12
  attr_accessor :finished_block
15
13
 
16
- def initialize(template_file_path, output_path, finished_block)
14
+ def initialize(template_file_path, output_path, options, finished_block)
17
15
  @template_file_path = template_file_path
18
16
  @output_path = output_path
17
+ @options = options
19
18
  @finished_block = finished_block
20
19
 
21
20
  im_version = fetch_image_magick_version
22
21
 
23
22
  if im_version
24
23
  print_image_magick_ancient_version_warning if im_version < RECENT_IM_VERSION
25
- if im_version < COLORSPACE_MIN_IM_VERSION
26
- @colorspace_in = "sRGB"
27
- @colorspace_out = "RGB"
28
- else
29
- @colorspace_in = "RGB"
30
- @colorspace_out = "sRGB"
31
- end
32
24
  else
33
25
  print_image_magick_no_version_warning
34
- @colorspace_in = "RGB"
35
- @colorspace_out = "sRGB"
36
26
  end
37
27
  end
38
28
 
@@ -78,30 +68,55 @@ module FaviconMaker
78
68
  def generate_file(template_file_path, output_file_path, size, format)
79
69
  case format.to_sym
80
70
  when :png
81
- image = MiniMagick::Image.open(template_file_path)
82
- image.define "png:include-chunk=none,trns,gama"
83
- image.colorspace colorspace_in
84
- image.resize size
85
- image.combine_options do |c|
86
- c.background "none"
87
- c.gravity "center"
88
- c.extent size
89
- end unless InputValidator.size_square?(size)
90
- image.format "png"
91
- image.strip
92
- image.colorspace colorspace_out
93
- image.write output_file_path
71
+ convert_settings = [
72
+ [ :define, "png:include-chunk=none,trns,gama" ],
73
+ [ :format, "png" ],
74
+ [ :resize, size ],
75
+ [ :gravity, "center" ],
76
+ [ :background, "none" ],
77
+ [ :extent, size ],
78
+ ]
79
+
80
+ run_convert(template_file_path, convert_settings, output_file_path, format)
94
81
  when :ico
95
- ico_cmd = "convert \"#{template_file_path}\" -quiet -colorspace #{colorspace_in} "
96
- escapes = "\\" unless on_windows?
97
- size.split(',').sort_by{|s| s.split('x')[0].to_i}.each do |s|
98
- ico_cmd << "#{escapes}( -clone 0 -resize #{s} #{escapes}) "
82
+ convert_settings = [
83
+ [ :quiet, nil ],
84
+ ]
85
+
86
+ center_settings = [
87
+ [ :gravity, "center" ],
88
+ [ :background, "none" ],
89
+ ]
90
+
91
+ run_convert(template_file_path, convert_settings, output_file_path, format) do |ico_cmd|
92
+ escapes = "\\" unless on_windows?
93
+ size.split(',').sort_by{|s| s.split('x')[0].to_i}.each do |s|
94
+ ico_cmd << "#{escapes}( -clone 0 -resize #{s} #{options_to_args(center_settings)} -extent #{s} #{escapes}) "
95
+ end
96
+ ico_cmd << "-delete 0"
99
97
  end
100
- ico_cmd << "-delete 0 -colorspace #{colorspace_out} \"#{output_file_path}\""
101
- print `#{ico_cmd}`
102
98
  end
103
99
  end
104
100
 
101
+ def run_convert(template_file_path, convert_settings, output_file_path, format, &block)
102
+ ico_cmd = "convert -background none #{@options} "
103
+ ico_cmd << "\"#{template_file_path}\" #{options_to_args(convert_settings)} "
104
+ ico_cmd = yield(ico_cmd) if block_given?
105
+ ico_cmd << " #{format}:\"#{output_file_path}\""
106
+ print `#{ico_cmd}`
107
+ end
108
+
109
+ def options_to_args(options)
110
+ return nil if options.nil?
111
+ options.map { |k,v|
112
+ if [ :xc, :null ].include?(k)
113
+ "#{k}:#{v}"
114
+ else
115
+ "-#{k} #{v}"
116
+ end
117
+ }.join(' ')
118
+ end
119
+
105
120
  def print_image_magick_ancient_version_warning
106
121
  puts "FaviconMaker: WARNING! Your installed ImageMagick version #{RECENT_IM_VERSION} is not up-to-date and might produce suboptimal output!"
107
122
  end
@@ -26,8 +26,8 @@ module FaviconMaker
26
26
  @config = Docile.dsl_eval(MakerConfig.new, &block)
27
27
  end
28
28
 
29
- def from(template_filename, &block)
30
- creators[template_filename] = block
29
+ def from(template_filename, options="", &block)
30
+ creators[template_filename] = [options, block]
31
31
  end
32
32
 
33
33
  def each_icon(&block)
@@ -35,9 +35,10 @@ module FaviconMaker
35
35
  end
36
36
 
37
37
  def start
38
- creators.each do |template_filename, creator_block|
38
+ creators.each do |template_filename, options_and_block|
39
39
  template_file = File.join(template_dir, template_filename)
40
- Docile.dsl_eval(Creator.new(template_file, output_dir, finished_block), &creator_block)
40
+ options, creator_block = *options_and_block
41
+ Docile.dsl_eval(Creator.new(template_file, output_dir, options, finished_block), &creator_block)
41
42
  end
42
43
  end
43
44
  end
@@ -1,8 +1,8 @@
1
1
  module FaviconMaker
2
2
  MAJOR = 1
3
- MINOR = 1
4
- PATCH = 2
3
+ MINOR = 2
4
+ PATCH = 1
5
5
  BUILD = nil
6
6
 
7
7
  VERSION = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
8
- end
8
+ end
@@ -5,8 +5,6 @@ describe FaviconMaker, '#create_versions' do
5
5
  let(:absolute_root_dir) { File.join(Dir.pwd, "spec") }
6
6
  let(:absolute_template_dir) { File.join(absolute_root_dir, "support") }
7
7
 
8
- let(:base_image) { "favicon base.png" }
9
-
10
8
  let(:output_path) { File.join(absolute_root_dir, relative_output_dir) }
11
9
 
12
10
  let(:total_count) { 19 }
@@ -20,6 +18,27 @@ describe FaviconMaker, '#create_versions' do
20
18
  end
21
19
  end
22
20
 
21
+ def extract_size(filepath)
22
+ matches = identify(filepath).match(/.*(PNG|ICO) (\d+x\d+).*/)
23
+ if matches && matches.size == 3
24
+ matches[2]
25
+ else
26
+ nil
27
+ end
28
+ end
29
+
30
+ def is_image_square?(filepath)
31
+ extract_size(filepath).split('x').uniq.size == 1
32
+ end
33
+
34
+ def is_file_image?(filepath)
35
+ !identify(filepath).match(/no decode delegate/).nil?
36
+ end
37
+
38
+ def identify(filepath)
39
+ `identify #{filepath}`
40
+ end
41
+
23
42
  context "multi-color icon" do
24
43
 
25
44
  let(:relative_output_dir) { "output1" }
@@ -36,7 +55,7 @@ describe FaviconMaker, '#create_versions' do
36
55
  FaviconMaker.generate do
37
56
 
38
57
  setup do
39
- template_dir absolute_template_dir
58
+ template_dir absolute_template_dir
40
59
  output_dir output_path
41
60
  end
42
61
 
@@ -148,4 +167,113 @@ describe FaviconMaker, '#create_versions' do
148
167
  # cleanup(output_path)
149
168
  end
150
169
  end
170
+
171
+ context "non-square icon" do
172
+
173
+ let(:relative_output_dir) { "output3" }
174
+
175
+ before do
176
+ cleanup(output_path)
177
+ Dir.mkdir(output_path)
178
+ end
179
+
180
+ subject do
181
+ files = []
182
+
183
+ FaviconMaker.generate do
184
+
185
+ setup do
186
+ template_dir absolute_template_dir
187
+ output_dir output_path
188
+ end
189
+
190
+ from "favicon_base_non_square.png" do
191
+ icon "apple-touch-icon-114x114-precomposed.png"
192
+ icon "apple-touch-icon-precomposed.png", size: "57x57"
193
+ icon "favicon.ico", size: "64x64,32x32,24x24,16x16"
194
+ icon "mstile-144x144", format: "png"
195
+ end
196
+
197
+ each_icon do |filepath|
198
+ files << filepath
199
+ end
200
+ end
201
+ files
202
+ end
203
+
204
+ it "creates multiple files" do
205
+ files = subject
206
+ expect(files.size).to eql(4)
207
+ files.each do |file|
208
+ expect(File.exists?(file)).to be_true
209
+ expect(is_image_square?(file)).to be_true
210
+ end
211
+ end
212
+
213
+ after do
214
+ # cleanup(output_path)
215
+ end
216
+ end
217
+
218
+ context "svg icon" do
219
+
220
+ let(:relative_output_dir) { "output4" }
221
+
222
+ before do
223
+ cleanup(output_path)
224
+ Dir.mkdir(output_path)
225
+ end
226
+
227
+ subject do
228
+ files = []
229
+
230
+ FaviconMaker.generate do
231
+
232
+ setup do
233
+ template_dir absolute_template_dir
234
+ output_dir output_path
235
+ end
236
+
237
+ from "TRS_Logo_RGB_solo.svg", '-background grey' do
238
+ icon "apple-touch-icon-152x152-precomposed.png"
239
+ icon "apple-touch-icon-144x144-precomposed.png"
240
+ icon "apple-touch-icon-120x120-precomposed.png"
241
+ icon "apple-touch-icon-114x114-precomposed.png"
242
+ icon "apple-touch-icon-76x76-precomposed.png"
243
+ icon "apple-touch-icon-72x72-precomposed.png"
244
+ icon "apple-touch-icon-60x60-precomposed.png"
245
+ icon "apple-touch-icon-57x57-precomposed.png"
246
+ icon "apple-touch-icon-precomposed.png", size: "57x57"
247
+ icon "apple-touch-icon.png", size: "57x57"
248
+ icon "favicon-196x196.png"
249
+ icon "favicon-160x160.png"
250
+ icon "favicon-96x96.png"
251
+ icon "favicon-32x32.png"
252
+ icon "favicon-16x16.png"
253
+ icon "favicon.png", size: "16x16"
254
+ icon "favicon.ico", size: "64x64,32x32,24x24,16x16"
255
+ icon "mstile-144x144", format: "png"
256
+ icon "mstile-310x150", format: "png"
257
+ end
258
+
259
+ each_icon do |filepath|
260
+ files << filepath
261
+ end
262
+ end
263
+ files
264
+ end
265
+
266
+ it "creates multiple image files" do
267
+ files = subject
268
+ expect(files.size).to eql(total_count)
269
+ files.each do |file|
270
+ expect(File.exists?(file)).to be_true
271
+ end
272
+ end
273
+
274
+ after do
275
+ # cleanup(output_path)
276
+ end
277
+ end
278
+
151
279
  end
@@ -0,0 +1,37 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!-- Generator: Adobe Illustrator 15.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
3
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
4
+ <svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="566.93px"
5
+ height="566.93px" viewBox="0 0 566.93 566.93" xml:space="preserve" fill="none">
6
+
7
+ <rect x="0" y="0" width="566.93" height="566.93" style="fill: #ffffff; stroke: #cccccc; strokeWidth: 2;" rx="80" ry="80" />
8
+ <g>
9
+ <path fill="#2D97AB" d="M485.617,141.689c6.428-11.785,10.024-30.518-6.509-47.051c-17.977-17.977-41.928-13.424-55.339-0.012
10
+ c-13.821,13.819-19.177,36.337-0.012,55.502c4.553,4.552,10.898,8.5,16.566,10.304c4.879,1.572,10.097-1.129,11.645-6.007
11
+ c1.572-4.878-1.144-10.106-6.009-11.643c-2.84-0.91-6.658-3.331-9.092-5.764c-12.736-12.737-5.461-23.811,0.012-29.282
12
+ c5.401-5.402,17.628-11.479,29.119,0.012c12.923,12.924,2.771,26.5,0.628,29.037c-3.167,3.681-2.957,9.175,0.477,12.609
13
+ l27.583,27.583c4.056,4.055,9.23,3.904,12.201,0.933c1.914-1.914,23.021-23.042,23.021-23.042
14
+ c5.073-5.938,8.219-13.132,9.593-22.309c2.84-23.775,8.732-71.721,10.047-82.396c1.969-16.009-9.559-27.698-25.333-25.824
15
+ l-81.363,9.802c-15.973,1.933-23.146,9.059-27.907,13.798L289.141,173.764l-61.996,6.486c-3.553,0.384-6.579,2.758-7.766,6.135
16
+ c-1.2,3.365-0.35,7.125,2.177,9.652l42.881,42.904l-101,101c-3.621,3.62-3.622,9.489-0.002,13.109
17
+ c3.623,3.622,9.491,3.62,13.113,0l107.534-107.535c3.621-3.62,3.621-9.488-0.002-13.109c-0.004-0.005-0.008-0.006-0.011-0.01
18
+ l-35.653-35.719l46.105-4.821c2.538-0.279,4.738-1.594,6.24-3.492L428.042,61.06c3.795-3.772,7.384-7.335,17.035-8.512
19
+ l81.349-9.791c4.539-0.513,5.309,0.397,4.702,5.146c-1.315,10.677-7.207,58.668-10.001,82.164
20
+ c-1.072,7.103-3.538,10.666-4.818,12.201l-15.057,15.056L485.617,141.689z"/>
21
+ <path fill="#547792" d="M81.722,430.851C81.269,430.282,35.7,372.229,35.7,293.173c-0.013-54.429,22.085-112.294,59.087-154.814
22
+ c30.271-34.789,84.702-76.273,172.001-76.274c29.328,0.011,57.992,7.557,76.89,13.901c4.844,1.63,10.105-0.979,11.735-5.844
23
+ c1.645-4.855-1.013-10.073-5.846-11.736c-20.187-6.776-50.949-14.857-82.78-14.857c-94.284,0-153.186,44.93-185.995,82.63
24
+ C40.344,172.659,17.15,233.528,17.163,293.173c-0.012,85.472,48.014,146.681,50.053,149.252c0.223,0.267,0.465,0.537,0.71,0.782
25
+ c3.282,3.282,8.594,3.653,12.328,0.685C84.25,440.69,84.914,434.856,81.722,430.851z"/>
26
+ <path fill="#2D97AB" d="M329.79,291.205l-71.568,71.546l-0.119,0.119c-3.62,3.62-3.623,9.487-0.001,13.109
27
+ c3.62,3.62,9.49,3.62,13.11-0.002l65.139-65.118l42.896,42.916c2.551,2.551,6.357,3.4,9.744,2.153
28
+ c3.389-1.247,5.751-4.354,6.043-7.952l5.193-63.36l84.341-84.387c3.623-3.622,3.623-9.49,0-13.112
29
+ c-3.62-3.62-9.489-3.62-13.111,0.002c0,0-86.004,85.982-86.155,86.11c-1.899,1.595-3.062,3.876-3.272,6.347l-3.842,46.92
30
+ l-35.288-35.293C339.279,287.583,333.41,287.585,329.79,291.205z"/>
31
+ <path fill="#5E5E84" d="M516.412,293.175c0.011-19.596-2.679-40.076-7.939-60.892c-1.247-4.95-6.301-7.954-11.271-6.708
32
+ c-4.961,1.258-7.965,6.311-6.706,11.27c4.9,19.316,7.369,38.271,7.381,56.329c-0.023,95.938-71.708,231.054-231.077,231.077
33
+ c-78.38-0.023-130.635-37.861-149.077-53.696l195.636-195.499c3.62-3.62,3.622-9.487,0-13.108c-3.62-3.621-9.489-3.621-13.109,0
34
+ L97.779,464.279c-3.62,3.62-3.633,9.478-0.012,13.1c0.023,0.023,0.058,0.057,0.081,0.079c7.09,7.091,68.414,65.316,168.952,65.33
35
+ C438.951,542.788,516.412,396.819,516.412,293.175z"/>
36
+ </g>
37
+ </svg>
metadata CHANGED
@@ -1,43 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: favicon_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Follmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-28 00:00:00.000000000 Z
11
+ date: 2014-05-29 00:00:00.000000000 Z
12
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: '3.7'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '3.7'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: docile
29
15
  requirement: !ruby/object:Gem::Requirement
30
16
  requirements:
31
17
  - - "~>"
32
18
  - !ruby/object:Gem::Version
33
- version: 1.1.3
19
+ version: '1.1'
34
20
  type: :runtime
35
21
  prerelease: false
36
22
  version_requirements: !ruby/object:Gem::Requirement
37
23
  requirements:
38
24
  - - "~>"
39
25
  - !ruby/object:Gem::Version
40
- version: 1.1.3
26
+ version: '1.1'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rspec
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +66,7 @@ extra_rdoc_files: []
80
66
  files:
81
67
  - ".gitignore"
82
68
  - ".rspec"
69
+ - ".ruby-version"
83
70
  - ".travis.yml"
84
71
  - Gemfile
85
72
  - Guardfile
@@ -96,8 +83,10 @@ files:
96
83
  - spec/favicon_maker_spec.rb
97
84
  - spec/input_validator_spec.rb
98
85
  - spec/spec_helper.rb
86
+ - spec/support/TRS_Logo_RGB_solo.svg
99
87
  - spec/support/favicon base.png
100
88
  - spec/support/favicon_base.png
89
+ - spec/support/favicon_base_non_square.png
101
90
  - spec/support/favicon_base_uni.png
102
91
  homepage: https://github.com/follmann/favicon_maker
103
92
  licenses: []
@@ -126,6 +115,8 @@ test_files:
126
115
  - spec/favicon_maker_spec.rb
127
116
  - spec/input_validator_spec.rb
128
117
  - spec/spec_helper.rb
118
+ - spec/support/TRS_Logo_RGB_solo.svg
129
119
  - spec/support/favicon base.png
130
120
  - spec/support/favicon_base.png
121
+ - spec/support/favicon_base_non_square.png
131
122
  - spec/support/favicon_base_uni.png