favicon_maker 0.2.4 → 0.3

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: 404740b87f448693d04a94f3162639fb35df1977
4
- data.tar.gz: 76a2784e2bbcdb8bc81db6ef7d197d83bc1f661b
3
+ metadata.gz: 7b2fef14009c845e3a40a3794579d66c12d0f40e
4
+ data.tar.gz: 8f8d56288229bf603dc326df4b872a2f4a61b4c4
5
5
  SHA512:
6
- metadata.gz: cb620d85eeea193ccfc242c7258c724200e017bdd169ee8f299293fbcb98198389d9951e038f14c049cb67548799d40dbed9a43cf1149852dc57e223aa62cc17
7
- data.tar.gz: 9fd87d36528d95b3d6be5a58dfc34fed240996b10a01ae98a3db6a53001fd40cd9c58814e26a5ace50a220850920ae2e4698fa61aa715f06adfbc23ce0f6a2d5
6
+ metadata.gz: 6fbfcfc6086db90c91d36a4f84394adb8bea4ada8101fb73b01c27a49d282c1938ba66e77743d233bcfc80d100c85542638b5e0fa5458e76d95aedf15923e835
7
+ data.tar.gz: 4ccd98ea5d07a56699ba295953c9dc6db1a2d3e2d4a4409da0ea2b18683f143e0393477e6376cec9388e20440d02b5ac366a715928173aa205ad571746e2bc5c
data/.gitignore CHANGED
@@ -4,4 +4,5 @@ Gemfile.lock
4
4
  pkg/*
5
5
  .rvmrc
6
6
 
7
- /spec/generated/
7
+ /spec/generated/
8
+ .DS_Store
data/README.md CHANGED
@@ -53,7 +53,7 @@ In order to integrate the FaviconMaker effortless into your [Middleman](https://
53
53
  Uses the following defaults:
54
54
 
55
55
  options = {
56
- :versions => [:apple_144, :apple_120, :apple_114, :apple_72, :apple_57, :apple_pre, :apple, :fav_png, :fav_ico],
56
+ :versions => [:apple_152, :apple_144, :apple_120, :apple_114, :apple_76, :apple_72, :apple_60, :apple_57, :apple, :fav_196, :fav_160, :fav_96, :fav_32, :fav_16, :fav_png, :fav_ico, :mstile_144],
57
57
  :custom_versions => {},
58
58
  :root_dir => File.dirname(__FILE__),
59
59
  :input_dir => "favicons",
@@ -66,11 +66,11 @@ Uses the following defaults:
66
66
  (untested attempted Rails integration, using all available options. Could be used in a Rake task or Capistrano recipe)
67
67
 
68
68
  options = {
69
- :versions => [:apple_144, :apple_120, :apple_114, :apple_57, :apple, :fav_png, :fav_ico],
69
+ :versions => [:apple_152, :apple_144, :apple_120, :apple_114, :apple_76, :apple_72, :apple_60, :apple_57, :apple, :fav_196, :fav_160, :fav_96, :fav_32, :fav_16, :fav_png, :fav_ico, :mstile_144],
70
70
  :custom_versions => {:apple_extreme_retina => {:filename => "apple-touch-icon-228x228-precomposed.png", :dimensions => "228x228", :format => "png"}},
71
71
  :root_dir => Rails.root,
72
72
  :input_dir => File.join("app", "assets", "public"),
73
- :base_image => "favico.png",
73
+ :base_image => "favicon.png",
74
74
  :output_dir => "public",
75
75
  :copy => true
76
76
  }
@@ -80,7 +80,7 @@ Uses the following defaults:
80
80
  end
81
81
 
82
82
  ## Base Image Guideline
83
- Choose the version with the biggest dimension as your base image. Currently the size 114x114 for newer iOS devices marks the upper limit. So just create a PNG with 24 or 32 Bit color depth and 114x114 document size. Downscaling of images always works better than upscaling.
83
+ Choose the version with the biggest dimension as your base image. Currently the size 196x196 for newer iOS devices marks the upper limit. So just create a PNG with 24 or 32 Bit color depth and 196x196 document size. Downscaling of images always works better than upscaling.
84
84
 
85
85
  ## Copyright
86
86
 
@@ -1,94 +1,142 @@
1
1
  module FaviconMaker
2
2
  require "mini_magick"
3
3
  require 'fileutils'
4
+ require 'pathname'
4
5
 
5
6
  class Generator
6
7
 
7
- ICON_VERSIONS = {
8
- :apple_144 => {:filename => "apple-touch-icon-144x144-precomposed.png", :sizes => "144x144", :format => "png"},
9
- :apple_120 => {:filename => "apple-touch-icon-120x120-precomposed.png", :sizes => "120x120", :format => "png"},
10
- :apple_114 => {:filename => "apple-touch-icon-114x114-precomposed.png", :sizes => "114x114", :format => "png"},
11
- :apple_72 => {:filename => "apple-touch-icon-72x72-precomposed.png", :sizes => "72x72", :format => "png"},
12
- :apple_57 => {:filename => "apple-touch-icon-57x57-precomposed.png", :sizes => "57x57", :format => "png"},
13
- :apple_pre => {:filename => "apple-touch-icon-precomposed.png", :sizes => "57x57", :format => "png"},
14
- :apple => {:filename => "apple-touch-icon.png", :sizes => "57x57", :format => "png"},
15
- :fav_png => {:filename => "favicon.png", :sizes => "16x16", :format => "png"},
16
- :fav_ico => {:filename => "favicon.ico", :sizes => "64x64,32x32,24x24,16x16", :format => "ico"}
8
+ ICON_VERSION_DEFINITIONS = {
9
+ :apple_152 => { :filename => "apple-touch-icon-152x152-precomposed.png", :sizes => "152x152", :format => "png" },
10
+ :apple_144 => { :filename => "apple-touch-icon-144x144-precomposed.png", :sizes => "144x144", :format => "png" },
11
+ :apple_120 => { :filename => "apple-touch-icon-120x120-precomposed.png", :sizes => "120x120", :format => "png" },
12
+ :apple_114 => { :filename => "apple-touch-icon-114x114-precomposed.png", :sizes => "114x114", :format => "png" },
13
+ :apple_76 => { :filename => "apple-touch-icon-76x76-precomposed.png", :sizes => "76x76", :format => "png" },
14
+ :apple_72 => { :filename => "apple-touch-icon-72x72-precomposed.png", :sizes => "72x72", :format => "png" },
15
+ :apple_60 => { :filename => "apple-touch-icon-60x60-precomposed.png", :sizes => "60x60", :format => "png" },
16
+ :apple_57 => { :filename => "apple-touch-icon-57x57-precomposed.png", :sizes => "57x57", :format => "png" },
17
+ :apple_pre => { :filename => "apple-touch-icon-precomposed.png", :sizes => "57x57", :format => "png" },
18
+ :apple => { :filename => "apple-touch-icon.png", :sizes => "57x57", :format => "png" },
19
+ :fav_196 => { :filename => "favicon-196x196.png", :sizes => "196x196", :format => "png" },
20
+ :fav_160 => { :filename => "favicon-160x160.png", :sizes => "160x160", :format => "png" },
21
+ :fav_96 => { :filename => "favicon-96x96.png", :sizes => "96x96", :format => "png" },
22
+ :fav_32 => { :filename => "favicon-32x32.png", :sizes => "32x32", :format => "png" },
23
+ :fav_16 => { :filename => "favicon-16x16.png", :sizes => "16x16", :format => "png" },
24
+ :fav_png => { :filename => "favicon.png", :sizes => "16x16", :format => "png" },
25
+ :fav_ico => { :filename => "favicon.ico", :sizes => "64x64,32x32,24x24,16x16", :format => "ico" },
26
+ :mstile_144 => { :filename => "mstile-144x144", :sizes => "144x144", :format => "png" }
17
27
  }
18
28
 
19
- IM_VERSION = (`convert --version`).scan(/ImageMagick (\d\.\d\.\d)/).flatten.first
20
- RECENT_VERSION = "6.8.0"
21
- COLORSPACE_MIN_VERSION = "6.7.5"
29
+ DEFAULT_OPTIONS = {
30
+ :versions => ICON_VERSION_DEFINITIONS.keys,
31
+ :custom_versions => {},
32
+ :root_dir => File.dirname(__FILE__),
33
+ :input_dir => "favicons",
34
+ :base_image => "favicon_base.png",
35
+ :output_dir => "favicons_output",
36
+ :copy => false
37
+ }
38
+
39
+ IM_VERSION = (`convert --version`).scan(/ImageMagick (\d\.\d\.\d)/).flatten.first
40
+ RECENT_VERSION = "6.8.0"
41
+ COLORSPACE_MIN_VERSION = "6.7.5"
42
+ COLORSPACE_IN, COLORSPACE_OUT = *(IM_VERSION < COLORSPACE_MIN_VERSION ? ["sRGB", "RGB"] : ["RGB", "sRGB"])
22
43
 
23
44
  class << self
24
45
 
25
46
  def create_versions(options={}, &block)
47
+ print_image_magick_warning if IM_VERSION < RECENT_VERSION
26
48
 
27
- puts "FaviconMaker: WARNING! Your installed ImageMagick version #{IM_VERSION} is not up-to-date and might produce suboptimal output!" if IM_VERSION < RECENT_VERSION
49
+ options = DEFAULT_OPTIONS.merge(options)
50
+ raise ArgumentError unless options[:versions].is_a? Array
28
51
 
29
- switch_colorspace = IM_VERSION < COLORSPACE_MIN_VERSION
52
+ base_path = File.join(options[:root_dir], options[:input_dir])
53
+ output_path = determine_output_path(options[:root_dir], options[:output_dir])
54
+ input_file_path = File.join(base_path, options[:base_image])
55
+ copy_composed = options[:copy]
30
56
 
31
- colorspace_conv = ["RGB", "sRGB"]
32
- colorspace_conv.reverse! if switch_colorspace
57
+ process_icon_versions(options[:versions], options[:custom_versions]) do |version|
58
+ build_mode, output_file_path = copy_or_generate_file(
59
+ input_file_path,
60
+ base_path,
61
+ output_path,
62
+ copy_composed,
63
+ version
64
+ )
33
65
 
34
- is_windows = (RbConfig::CONFIG['host_os'].match /mswin|mingw|cygwin/)
66
+ if block_given?
67
+ yield output_file_path, build_mode
68
+ end
69
+ end
70
+ end
35
71
 
36
- options = {
37
- :versions => ICON_VERSIONS.keys,
38
- :custom_versions => {},
39
- :root_dir => File.dirname(__FILE__),
40
- :input_dir => "favicons",
41
- :base_image => "favicon_base.png",
42
- :output_dir => "favicons_output",
43
- :copy => false
44
- }.merge(options)
72
+ private
45
73
 
46
- raise ArgumentError unless options[:versions].is_a? Array
47
- base_path = File.join(options[:root_dir], options[:input_dir])
48
- input_file = File.join(base_path, options[:base_image])
49
-
50
- icon_versions = ICON_VERSIONS.merge(options[:custom_versions])
51
- (options[:versions] + options[:custom_versions].keys).uniq.each do |version|
52
- version = icon_versions[version]
53
- sizes = version[:dimensions] || version[:sizes]
54
- composed_path = File.join(base_path, version[:filename])
55
- output_path = File.join(options[:root_dir], options[:output_dir])
56
- output_file = File.join(output_path, version[:filename])
57
-
58
- build_mode = nil
59
- # check for self composed icon file
60
- if File.exist?(composed_path) && options[:copy]
61
- FileUtils.cp composed_path, output_file
62
- build_mode = :copied
63
- else
64
- case version[:format].to_sym
65
- when :png
66
- image = MiniMagick::Image.open(input_file)
67
- image.define "png:include-chunk=none,trns,gama"
68
- image.colorspace colorspace_conv.first
69
- image.resize sizes
70
- image.format "png"
71
- image.strip
72
- image.colorspace colorspace_conv.last
73
- image.write output_file
74
- when :ico
75
- ico_cmd = "convert \"#{input_file}\" -colorspace #{colorspace_conv.first} "
76
- escapes = "\\" unless is_windows
77
- sizes.split(',').sort_by{|s| s.split('x')[0].to_i}.each do |size|
78
- ico_cmd << "#{escapes}( -clone 0 -colors 256 -resize #{size} #{escapes}) "
79
- end
80
- ico_cmd << "-delete 0 -colors 256 -colorspace #{colorspace_conv.last} \"#{File.join(output_path, version[:filename])}\""
81
- puts `#{ico_cmd}`
82
- end
83
- build_mode = :generated
84
- end
74
+ def copy_or_generate_file(input_file_path, base_path, output_path, copy_composed, version)
75
+ sizes = version[:dimensions] || version[:sizes]
76
+ composed_file_path = File.join(base_path, version[:filename])
77
+ output_file_path = File.join(output_path, version[:filename])
78
+ output_format = version[:format]
85
79
 
86
- if block_given?
87
- yield output_file, build_mode
80
+ # check for self composed icon file
81
+ if copy_composed && File.exist?(composed_file_path)
82
+ copy_image(composed_file_path, output_file_path)
83
+ return :copied, output_file_path
84
+ else
85
+ generate_file(output_format, sizes, input_file_path, output_file_path)
86
+ return :generated, output_file_path
87
+ end
88
+ end
89
+
90
+ def generate_file(format, sizes, input_file_path, output_file_path)
91
+ case format.to_sym
92
+ when :png
93
+ image = MiniMagick::Image.open(input_file_path)
94
+ image.define "png:include-chunk=none,trns,gama"
95
+ image.colorspace COLORSPACE_IN
96
+ image.resize sizes
97
+ image.format "png"
98
+ image.strip
99
+ image.colorspace COLORSPACE_OUT
100
+ image.write output_file_path
101
+ when :ico
102
+ ico_cmd = "convert \"#{input_file_path}\" -colorspace #{COLORSPACE_IN} "
103
+ escapes = "\\" unless on_windows?
104
+ sizes.split(',').sort_by{|s| s.split('x')[0].to_i}.each do |size|
105
+ ico_cmd << "#{escapes}( -clone 0 -resize #{size} #{escapes}) "
88
106
  end
107
+ ico_cmd << "-delete 0 -colorspace #{COLORSPACE_OUT} \"#{output_file_path}\""
108
+ puts `#{ico_cmd}`
89
109
  end
90
110
  end
91
111
 
112
+ def copy_image(composed_file_path, output_file_path)
113
+ FileUtils.cp(composed_file_path, output_file_path)
114
+ end
115
+
116
+ def determine_output_path(root_dir, output_dir)
117
+ if Pathname.new(output_dir).absolute?
118
+ output_dir
119
+ else
120
+ File.join(root_dir, output_dir)
121
+ end
122
+ end
123
+
124
+ def process_icon_versions(versions, custom_versions, &block)
125
+ icon_versions_available = ICON_VERSION_DEFINITIONS.merge(custom_versions)
126
+
127
+ (versions + custom_versions.keys).uniq.each do |version_label|
128
+ yield icon_versions_available[version_label]
129
+ end
130
+ end
131
+
132
+ def print_image_magick_warning
133
+ puts "FaviconMaker: WARNING! Your installed ImageMagick version #{IM_VERSION} is not up-to-date and might produce suboptimal output!"
134
+ end
135
+
136
+ def on_windows?
137
+ (RbConfig::CONFIG['host_os'].match /mswin|mingw|cygwin/)
138
+ end
139
+
92
140
  end
93
141
  end
94
142
  end
@@ -1,3 +1,3 @@
1
1
  module FaviconMaker
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3"
3
3
  end
@@ -1,12 +1,35 @@
1
1
  require 'spec_helper'
2
+
2
3
  describe FaviconMaker, '#create_versions' do
3
4
 
4
5
  before(:all) do
5
6
  @multi_versions = []
6
7
  @uni_versions = []
7
8
  @options = {
8
- :versions => [:apple_144, :apple_120, :apple_114, :apple_72, :apple_57, :apple, :fav_png, :fav_ico],
9
- :custom_versions => {:apple_extreme_retina => {:filename => "apple-touch-icon-228x228-precomposed.png", :sizes => "228x228", :format => "png"}},
9
+ :versions => [
10
+ :apple_152,
11
+ :apple_144,
12
+ :apple_120,
13
+ :apple_114,
14
+ :apple_76,
15
+ :apple_72,
16
+ :apple_60,
17
+ :apple_57,
18
+ :apple,
19
+ :fav_196,
20
+ :fav_160,
21
+ :fav_96,
22
+ :fav_32,
23
+ :fav_16,
24
+ :fav_png,
25
+ :fav_ico,
26
+ :mstile_144
27
+ ],
28
+ :custom_versions => {
29
+ :apple_extreme_retina => {
30
+ :filename => "apple-touch-icon-228x228-precomposed.png", :sizes => "228x228", :format => "png"
31
+ }
32
+ },
10
33
  :root_dir => File.join(Dir.pwd, "spec"),
11
34
  :input_dir => "support",
12
35
  :copy => true
@@ -40,8 +63,8 @@ describe FaviconMaker, '#create_versions' do
40
63
  end
41
64
  end
42
65
 
43
- it "creates 9 different versions" do
44
- @multi_versions.size.should eql(9)
66
+ it "creates 18 different versions" do
67
+ @multi_versions.size.should eql(18)
45
68
  end
46
69
 
47
70
  it "creates files for versions" do
@@ -75,8 +98,8 @@ describe FaviconMaker, '#create_versions' do
75
98
  end
76
99
  end
77
100
 
78
- it "creates 9 different versions" do
79
- @uni_versions.size.should eql(9)
101
+ it "creates 18 different versions" do
102
+ @uni_versions.size.should eql(18)
80
103
  end
81
104
 
82
105
  it "creates files for versions" do
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.2.4
4
+ version: '0.3'
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-12-10 00:00:00.000000000 Z
11
+ date: 2014-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick