makeicon 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/makeicon +4 -1
- data/lib/makeicon/version.rb +1 -1
- data/lib/makeicon.rb +178 -2
- 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: 5b5243afb327e7d9193a72c1134a5f32dddf42b6
|
4
|
+
data.tar.gz: befd5fc35831e6b534d81f6feefda6df2014a980
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2193c651282d10f28f653681ada313937d36fd6ec03a53d364c45bbe632fd5d02be0909607bdbda88af98af19f729fe378fd769e6bf5a88b392aa1a343bd25ae
|
7
|
+
data.tar.gz: aab875e112647bdb04e0b8f69bc4ede890125cce3a8db24c044d1cd2132fcdc1f02909ad639ad5c03e1f9a5afd6f82acd6721d117a9d964074284c4d1cc73be7
|
data/bin/makeicon
CHANGED
data/lib/makeicon/version.rb
CHANGED
data/lib/makeicon.rb
CHANGED
@@ -1,5 +1,181 @@
|
|
1
1
|
require "makeicon/version"
|
2
2
|
|
3
|
-
module
|
4
|
-
|
3
|
+
module MakeIcon
|
4
|
+
module Helper
|
5
|
+
class AppiconHelper
|
6
|
+
def self.check_input_image_size(image, size)
|
7
|
+
puts "Minimum width of input image should be #{size}" if image.width < size
|
8
|
+
puts "Minimum height of input image should be #{size}" if image.height < size
|
9
|
+
puts "Input image should be square" if image.width != image.height
|
10
|
+
# UI.user_error!("Minimum width of input image should be #{size}") if image.width < size
|
11
|
+
# UI.user_error!("Minimum height of input image should be #{size}") if image.height < size
|
12
|
+
# UI.user_error!("Input image should be square") if image.width != image.height
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class SocialAction
|
18
|
+
def self.get_needed_icons(device, needed_icons, is_android = false, custom_sizes = {})
|
19
|
+
icons = []
|
20
|
+
puts device
|
21
|
+
needed_icons[device].each do |scale, sizes|
|
22
|
+
sizes.each do |size|
|
23
|
+
if size.kind_of?(Array)
|
24
|
+
size, role, subtype = size
|
25
|
+
end
|
26
|
+
|
27
|
+
if is_android
|
28
|
+
width, height = size.split('x').map { |v| v.to_f }
|
29
|
+
else
|
30
|
+
width, height = size.split('x').map { |v| v.to_f * scale.to_i }
|
31
|
+
end
|
32
|
+
|
33
|
+
icons << {
|
34
|
+
'width' => width,
|
35
|
+
'height' => height,
|
36
|
+
'size' => size,
|
37
|
+
'device' => device.to_s.gsub('_', '-'),
|
38
|
+
'scale' => scale,
|
39
|
+
'role' => role,
|
40
|
+
'subtype' => subtype
|
41
|
+
}
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Add custom icon sizes (probably for notifications)
|
46
|
+
custom_sizes.each do |path, size|
|
47
|
+
path = path.to_s
|
48
|
+
width, height = size.split('x').map { |v| v.to_f }
|
49
|
+
|
50
|
+
icons << {
|
51
|
+
'width' => width,
|
52
|
+
'height' => height,
|
53
|
+
'size' => size,
|
54
|
+
'basepath' => File.dirname(path),
|
55
|
+
'filename' => File.basename(path)
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
# Sort from the largest to the smallest needed icon
|
60
|
+
icons = icons.sort_by {|value| value['width']} .reverse
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.needed_icons
|
64
|
+
{
|
65
|
+
social: {
|
66
|
+
'weixin' => ['28x28','108x108'],
|
67
|
+
'weibo' => ['16x16','80x80','120x120'],
|
68
|
+
'qq' => ['16x16','512x512'],
|
69
|
+
},
|
70
|
+
}
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.notification_icons(path, filename)
|
74
|
+
return {} if !path || !filename
|
75
|
+
|
76
|
+
{
|
77
|
+
"#{path}-ldpi/#{filename}" => '36x36',
|
78
|
+
"#{path}-mdpi/#{filename}" => '24x24',
|
79
|
+
"#{path}-hdpi/#{filename}" => '36x36',
|
80
|
+
"#{path}-xhdpi/#{filename}" => '48x48',
|
81
|
+
"#{path}-xxhdpi/#{filename}" => '72x72',
|
82
|
+
"#{path}-xxxhdpi/#{filename}" => '96x96',
|
83
|
+
}
|
84
|
+
end
|
85
|
+
|
86
|
+
def self.run(params)
|
87
|
+
fname = params[:appicon_image_file]
|
88
|
+
|
89
|
+
require 'mini_magick'
|
90
|
+
image = MiniMagick::Image.open(fname)
|
91
|
+
|
92
|
+
Helper::AppiconHelper.check_input_image_size(image, 512)
|
93
|
+
|
94
|
+
# Convert image to png
|
95
|
+
image.format 'png'
|
96
|
+
|
97
|
+
# Merge notification icons into customer sizes as they are handled thes same way
|
98
|
+
|
99
|
+
icons = get_needed_icons(:social, self.needed_icons, true)
|
100
|
+
icons.each do |icon|
|
101
|
+
width = icon['width']
|
102
|
+
height = icon['height']
|
103
|
+
|
104
|
+
# Custom icons will have basepath and filename already defined
|
105
|
+
if icon.has_key?('basepath') && icon.has_key?('filename')
|
106
|
+
basepath = Pathname.new(icon['basepath'])
|
107
|
+
filename = icon['filename']
|
108
|
+
else
|
109
|
+
basepath = Pathname.new("#{params[:appicon_path]}-#{icon['scale']}")
|
110
|
+
filename = "#{params[:appicon_filename]}_#{width}x#{height}.png"
|
111
|
+
end
|
112
|
+
FileUtils.mkdir_p(basepath)
|
113
|
+
|
114
|
+
image.resize "#{width}x#{height}"
|
115
|
+
image.write basepath + filename
|
116
|
+
end
|
117
|
+
|
118
|
+
puts "Successfully stored launcher icons at '#{params[:appicon_path]}'"
|
119
|
+
end
|
120
|
+
|
121
|
+
def self.get_custom_sizes(image, custom_sizes)
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.description
|
126
|
+
"Generate required icon sizes from a master application icon"
|
127
|
+
end
|
128
|
+
|
129
|
+
def self.authors
|
130
|
+
["@adrum"]
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.available_options
|
134
|
+
[
|
135
|
+
FastlaneCore::ConfigItem.new(key: :appicon_image_file,
|
136
|
+
env_name: "APPICON_IMAGE_FILE",
|
137
|
+
description: "Path to a square image file, at least 512x512",
|
138
|
+
optional: false,
|
139
|
+
type: String),
|
140
|
+
FastlaneCore::ConfigItem.new(key: :appicon_devices,
|
141
|
+
env_name: "APPICON_DEVICES",
|
142
|
+
default_value: [:phone],
|
143
|
+
description: "Array of device types to generate icons for",
|
144
|
+
optional: true,
|
145
|
+
type: Array),
|
146
|
+
FastlaneCore::ConfigItem.new(key: :appicon_path,
|
147
|
+
env_name: "APPICON_PATH",
|
148
|
+
default_value: 'app/res/mipmap/',
|
149
|
+
description: "Path to res subfolder",
|
150
|
+
optional: true,
|
151
|
+
type: String),
|
152
|
+
FastlaneCore::ConfigItem.new(key: :appicon_filename,
|
153
|
+
env_name: "APPICON_FILENAME",
|
154
|
+
default_value: 'ic_launcher',
|
155
|
+
description: "The output filename of each image",
|
156
|
+
optional: true,
|
157
|
+
type: String),
|
158
|
+
FastlaneCore::ConfigItem.new(key: :appicon_notification_icon_path,
|
159
|
+
env_name: "APPICON_NOTIFICATION_ICON_PATH",
|
160
|
+
default_value: 'app/res/drawable/',
|
161
|
+
description: "Path to res subfolder",
|
162
|
+
optional: true,
|
163
|
+
type: String),
|
164
|
+
FastlaneCore::ConfigItem.new(key: :appicon_notification_icon_filename,
|
165
|
+
env_name: "APPICON_NOTIFICATION_ICON_FILENAME",
|
166
|
+
default_value: 'ic_stat_onesignal_default',
|
167
|
+
description: "File name for notification icons",
|
168
|
+
optional: true,
|
169
|
+
type: String),
|
170
|
+
FastlaneCore::ConfigItem.new(key: :appicon_custom_sizes,
|
171
|
+
description: "Hash of custom sizes - {'path/icon.png' => '256x256'}",
|
172
|
+
optional: true,
|
173
|
+
type: Hash)
|
174
|
+
]
|
175
|
+
end
|
176
|
+
|
177
|
+
def self.is_supported?(platform)
|
178
|
+
[:android].include?(platform)
|
179
|
+
end
|
180
|
+
end
|
5
181
|
end
|