favicon_maker 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OGY1MThiYmRlODczZWE3YjY0NGQzZmE0Mjk4ODg4YzgyNTM0ZWU4Mg==
4
+ MWRhN2RjOGI4OTRlMWI3ODA5NjYzNjA0MmJhYjllYmUzNmI5Y2Y0MA==
5
5
  data.tar.gz: !binary |-
6
- OTRlNWI4MjlkZWY5NzI0ZGE1YjMzNjkxZjZhYmU0NzE1YzI1MDlmNg==
6
+ Yjk3YmZhMmZkOGI2NWViZDcyNGZlOTQyMzRlMzNhNThkM2NhNjE4Yw==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- OTZhYjVlNzRmNGE3NDA3ZGYzZjE5YjIyMGQzZWQ1NTFlMmZjOTEyYWQ5Yjhk
10
- NzRjZDljOGZkODM4MGU4NGU1NTAyMzYyODI2YzRkMjVkMGQxMDI1YmVlNTA1
11
- ZDIyZDY0NjllMTVkNmE3ZTNjYmMxNmNjMDE2MThlMTg0MWEyYWY=
9
+ ZDA1ZjE3ZTcxOTE5MjYzYWNmMTMxMDcxNDJiMTM3OWJmYmRkZDEyNDFmM2Yy
10
+ MmI0MTdjNzFlODE5N2Y1ZjQwODQ4M2IwZTJiNjEyNDUzOGU5OTc2MDI3NDVk
11
+ MDA2YTY0OTQ5YjM1YWE3YjgzNTE5MTBjMmNhN2Q4MTgzNzVmZjc=
12
12
  data.tar.gz: !binary |-
13
- NjQxMGJiMWU0NjdlZDM2MDg4MmEzMTAyMTAyZGZmYzE1NTE2NGE2MzIyYWM3
14
- MTA0MTM5ZTNiMjhkMTY3NDc0ZGEyMGZjZjY5ZGQ3NzdiYmRhYjAzYzI5ZDM2
15
- MmU0YTg4MjRkZTA0NWIwNDk5ZTc4MWYwNDE2NDIwOWRhZGFmNWM=
13
+ YWM3ZTYxYTY3ZWU2YzI2YjcwMTdjYTY5ODNlNTAyYTdjMGUxNDNlN2RlNDM1
14
+ MzcxZWRlM2Y2OWE0ZTk5ZWVmMWQzMTM3NThlN2U1MmUyZTdhYTk0MWI0NTM4
15
+ MDg5ZTYwNjcxZTYwNzRjYmZhODZhOGI1NDQ2ZDkwYjM2YjZjZDk=
data/.gitignore CHANGED
@@ -3,3 +3,5 @@
3
3
  Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
+
7
+ /spec/generated/
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  rvm:
2
- - 1.8.7
3
2
  - 1.9.2
3
+ - 1.9.3
4
+ - 2.0.0
4
5
  script: "bundle exec rspec spec"
@@ -5,14 +5,14 @@ module FaviconMaker
5
5
  class Generator
6
6
 
7
7
  ICON_VERSIONS = {
8
- :apple_144 => {:filename => "apple-touch-icon-144x144-precomposed.png", :dimensions => "144x144", :format => "png"},
9
- :apple_114 => {:filename => "apple-touch-icon-114x114-precomposed.png", :dimensions => "114x114", :format => "png"},
10
- :apple_72 => {:filename => "apple-touch-icon-72x72-precomposed.png", :dimensions => "72x72", :format => "png"},
11
- :apple_57 => {:filename => "apple-touch-icon-57x57-precomposed.png", :dimensions => "57x57", :format => "png"},
12
- :apple_pre => {:filename => "apple-touch-icon-precomposed.png", :dimensions => "57x57", :format => "png"},
13
- :apple => {:filename => "apple-touch-icon.png", :dimensions => "57x57", :format => "png"},
14
- :fav_png => {:filename => "favicon.png", :dimensions => "16x16", :format => "png"},
15
- :fav_ico => {:filename => "favicon.ico", :dimensions => "16x16", :format => "ico"}
8
+ :apple_144 => {:filename => "apple-touch-icon-144x144-precomposed.png", :sizes => "144x144", :format => "png"},
9
+ :apple_114 => {:filename => "apple-touch-icon-114x114-precomposed.png", :sizes => "114x114", :format => "png"},
10
+ :apple_72 => {:filename => "apple-touch-icon-72x72-precomposed.png", :sizes => "72x72", :format => "png"},
11
+ :apple_57 => {:filename => "apple-touch-icon-57x57-precomposed.png", :sizes => "57x57", :format => "png"},
12
+ :apple_pre => {:filename => "apple-touch-icon-precomposed.png", :sizes => "57x57", :format => "png"},
13
+ :apple => {:filename => "apple-touch-icon.png", :sizes => "57x57", :format => "png"},
14
+ :fav_png => {:filename => "favicon.png", :sizes => "16x16", :format => "png"},
15
+ :fav_ico => {:filename => "favicon.ico", :sizes => "64x64,32x32,24x24,16x16", :format => "ico"}
16
16
  }
17
17
 
18
18
  class << self
@@ -30,33 +30,43 @@ module FaviconMaker
30
30
 
31
31
  raise ArgumentError unless options[:versions].is_a? Array
32
32
  base_path = File.join(options[:root_dir], options[:input_dir])
33
- input_path = File.join(base_path, options[:base_image])
33
+ input_file = File.join(base_path, options[:base_image])
34
34
 
35
35
  icon_versions = ICON_VERSIONS.merge(options[:custom_versions])
36
36
  (options[:versions] + options[:custom_versions].keys).uniq.each do |version|
37
37
  version = icon_versions[version]
38
+ sizes = version[:dimensions] || version[:sizes]
38
39
  composed_path = File.join(base_path, version[:filename])
39
- output_path = File.join(options[:root_dir], options[:output_dir], version[:filename])
40
+ output_path = File.join(options[:root_dir], options[:output_dir])
41
+ output_file = File.join(output_path, version[:filename])
40
42
 
41
43
  build_mode = nil
42
44
  # check for self composed icon file
43
- if File.exist?(composed_path)
44
- if options[:copy]
45
- FileUtils.cp composed_path, output_path
46
- build_mode = :copied
47
- end
45
+ if File.exist?(composed_path) && options[:copy]
46
+ FileUtils.cp composed_path, output_file
47
+ build_mode = :copied
48
48
  else
49
- image = MiniMagick::Image.open(input_path)
50
- image.define "png:include-chunk=none,trns,gama"
51
- image.resize version[:dimensions]
52
- image.format version[:format]
53
- image.flatten
54
- image.write output_path
49
+ image = MiniMagick::Image.open(input_file)
50
+ case version[:format].to_sym
51
+ when :png
52
+ image.define "png:include-chunk=none,trns,gama"
53
+ image.resize sizes
54
+ image.format "png"
55
+ image.strip
56
+ image.write output_file
57
+ when :ico
58
+ ico_cmd = "convert #{input_file} -colorspace RGB "
59
+ sizes.split(',').sort_by{|s| s.split('x')[0].to_i}.each do |size|
60
+ ico_cmd << "\\( -clone 0 -colors 256 -resize #{size} \\) "
61
+ end
62
+ ico_cmd << "-delete 0 -colors 256 -colorspace sRGB #{File.join(output_path, version[:filename])}"
63
+ puts `#{ico_cmd}`
64
+ end
55
65
  build_mode = :generated
56
66
  end
57
67
 
58
68
  if block_given?
59
- yield output_path, build_mode
69
+ yield output_file, build_mode
60
70
  end
61
71
  end
62
72
  end
@@ -1,3 +1,3 @@
1
1
  module FaviconMaker
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -2,39 +2,93 @@ require 'spec_helper'
2
2
  describe FaviconMaker, '#create_versions' do
3
3
 
4
4
  before(:all) do
5
- @versions = []
6
- options = {
5
+ @multi_versions = []
6
+ @uni_versions = []
7
+ @options = {
7
8
  :versions => [:apple_144, :apple_114, :apple_72, :apple_57, :apple, :fav_png, :fav_ico],
8
- :custom_versions => {:apple_extreme_retina => {:filename => "apple-touch-icon-228x228-precomposed.png", :dimensions => "228x228", :format => "png"}},
9
+ :custom_versions => {:apple_extreme_retina => {:filename => "apple-touch-icon-228x228-precomposed.png", :sizes => "228x228", :format => "png"}},
9
10
  :root_dir => File.join(Dir.pwd, "spec"),
10
11
  :input_dir => "support",
11
- :base_image => "favicon_base.png",
12
- :output_dir => "generated",
13
12
  :copy => true
14
13
  }
15
14
 
16
- @generated_dir = File.join(options[:root_dir], options[:output_dir])
17
- Dir.mkdir(@generated_dir)
18
-
19
- FaviconMaker::Generator.create_versions(options) do |filepath, status|
20
- @versions << filepath
15
+ @cleanup = lambda do |output_dir|
16
+ if Dir.exists?(output_dir)
17
+ Dir[File.join(output_dir, "*")].each do |file|
18
+ File.delete(file)
19
+ end
20
+ Dir.delete(output_dir)
21
+ end
21
22
  end
22
23
  end
23
24
 
24
- it "creates 8 different versions" do
25
- @versions.size.should eql(8)
26
- end
25
+ context "multi-color icon" do
26
+ before do
27
+ options = @options.merge({
28
+ :base_image => "favicon_base.png",
29
+ :output_dir => "output1"
30
+ })
31
+
32
+ @output_dir = File.join(options[:root_dir], options[:output_dir])
33
+
34
+ @cleanup.call(@output_dir)
35
+
36
+ Dir.mkdir(@output_dir)
37
+
38
+ FaviconMaker::Generator.create_versions(options) do |filepath, status|
39
+ @multi_versions << filepath
40
+ end
41
+ end
27
42
 
28
- it "creates files for versions" do
29
- @versions.each do |file|
30
- File.exists?(file).should be_true
43
+ it "creates 8 different versions" do
44
+ @multi_versions.size.should eql(8)
31
45
  end
46
+
47
+ it "creates files for versions" do
48
+ @multi_versions.each do |file|
49
+ File.exists?(file).should be_true
50
+ end
51
+ end
52
+
53
+ after do
54
+ # @cleanup.call(@output_dir)
55
+ end
56
+
32
57
  end
33
58
 
34
- after(:all) do
35
- @versions.each do |file|
36
- File.delete(file)
59
+ context "uni-color icon" do
60
+
61
+ before do
62
+ options = @options.merge({
63
+ :base_image => "favicon_base_uni.png",
64
+ :output_dir => "output2"
65
+ })
66
+
67
+ @output_dir = File.join(options[:root_dir], options[:output_dir])
68
+
69
+ @cleanup.call(@output_dir)
70
+
71
+ Dir.mkdir(@output_dir)
72
+
73
+ FaviconMaker::Generator.create_versions(options) do |filepath, status|
74
+ @uni_versions << filepath
75
+ end
76
+ end
77
+
78
+ it "creates 8 different versions" do
79
+ @uni_versions.size.should eql(8)
37
80
  end
38
- Dir.delete(@generated_dir)
81
+
82
+ it "creates files for versions" do
83
+ @uni_versions.each do |file|
84
+ File.exists?(file).should be_true
85
+ end
86
+ end
87
+
88
+ after do
89
+ # @cleanup.call(@output_dir)
90
+ end
91
+
39
92
  end
93
+
40
94
  end
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: favicon_maker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Follmann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-09 00:00:00.000000000 Z
11
+ date: 2013-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick
@@ -57,6 +57,7 @@ files:
57
57
  - spec/favicon_maker_spec.rb
58
58
  - spec/spec_helper.rb
59
59
  - spec/support/favicon_base.png
60
+ - spec/support/favicon_base_uni.png
60
61
  homepage: https://github.com/follmann/favicon_maker
61
62
  licenses: []
62
63
  metadata: {}
@@ -84,3 +85,4 @@ test_files:
84
85
  - spec/favicon_maker_spec.rb
85
86
  - spec/spec_helper.rb
86
87
  - spec/support/favicon_base.png
88
+ - spec/support/favicon_base_uni.png