yamg 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +8 -0
- data/.hound.yml +2 -0
- data/.travis.yml +10 -0
- data/Gemfile +15 -0
- data/Guardfile +26 -0
- data/MIT-LICENSE +19 -0
- data/README.md +28 -0
- data/Rakefile +11 -0
- data/bin/yamg +9 -0
- data/lib/yamg/version.rb +4 -0
- data/lib/yamg.rb +419 -0
- data/yamg.gemspec +25 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 07b978bbab7904b6f351c73369b99c0ebe73aba4
|
4
|
+
data.tar.gz: d61104395d6d0b0a4183a2f59cea154fe914a9e1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b0fb6c6605da534052839b5c190f795f698024c6e4a584be5a80be4314ade72bbafc991fde4e024191b262006380af03391feb3755eb5cd7e6addb48396bf08
|
7
|
+
data.tar.gz: 754417d1dcd6e6b23f2626638a6708502f4d33e80066b0290a15bac718140cade9401125ce09cb8f714ed1d045c77b9be77ba04c78042708f093a298a7e6232e
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.hound.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in phonie-codes.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :test do
|
7
|
+
gem 'rake'
|
8
|
+
gem 'psych'
|
9
|
+
gem 'rubocop'
|
10
|
+
gem 'guard'
|
11
|
+
gem 'guard-rubocop'
|
12
|
+
gem 'minitest'
|
13
|
+
gem 'guard-minitest'
|
14
|
+
gem 'coveralls', require: false
|
15
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
## Uncomment and set this to only include directories you want to watch
|
5
|
+
# directories %w(app lib config test spec feature)
|
6
|
+
|
7
|
+
## Uncomment to clear the screen before every task
|
8
|
+
# clearing :on
|
9
|
+
|
10
|
+
guard :minitest do
|
11
|
+
# with Minitest::Unit
|
12
|
+
# watch(%r{^test/(.*)\/?test_(.*)\.rb$})
|
13
|
+
# watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
14
|
+
# watch(%r{^test/test_helper\.rb$}) { 'test' }
|
15
|
+
|
16
|
+
# with Minitest::Spec
|
17
|
+
watch(%r{^spec/(.*)_spec\.rb$})
|
18
|
+
watch(%r{^lib/(.+)\.rb$}) { 'spec' }
|
19
|
+
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
20
|
+
watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
|
21
|
+
end
|
22
|
+
|
23
|
+
guard :rubocop do
|
24
|
+
watch(/.+\.rb$/)
|
25
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
26
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2014-2015 Yamg Authors
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
copy of this software and associated documentation files (the "Software"),
|
5
|
+
to deal in the Software without restriction, including without limitation
|
6
|
+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
7
|
+
and/or sell copies of the Software, and to permit persons to whom the
|
8
|
+
Software is furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be
|
11
|
+
included in all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
14
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
15
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
16
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
17
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
18
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
19
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# YAMG
|
2
|
+
|
3
|
+
|
4
|
+
_____ _____ _____ ______ _______ _____
|
5
|
+
|\ \ / /| ___|\ \ | \/ \ ___|\ \
|
6
|
+
| \ \ / / | / /\ \ / /\ \ / /\ \
|
7
|
+
| \____\/ / /| | | | / /\ / /\ || | |____|
|
8
|
+
\ | / / / | |__| | / /\ \_/ / / /|| | ____
|
9
|
+
\|___/ / / | .--. || | \|_|/ / / || | | |
|
10
|
+
/ / / | | | || | | | || | |_, |
|
11
|
+
/____/ / |____| |____||\____\ |____| /|\ ___\___/ /|
|
12
|
+
|` | / | | | || | | | | / | | /____ / |
|
13
|
+
|_____|/ |____| |____| \|____| |____|/ \|___| | /
|
14
|
+
\|____|/
|
15
|
+
|
16
|
+
|
17
|
+
[![Gem Version](https://badge.fury.io/rb/yamg.png)](http://badge.fury.io/rb/yamg)
|
18
|
+
[![Dependency Status](https://gemnasium.com/nofxx/yamg.svg)](https://gemnasium.com/nofxx/yamg)
|
19
|
+
[![Build Status](https://travis-ci.org/nofxx/yamg.png?branch=master)](https://travis-ci.org/nofxx/yamg)
|
20
|
+
|
21
|
+
YAMG
|
22
|
+
|
23
|
+
## Install
|
24
|
+
|
25
|
+
gem 'yamg'
|
26
|
+
|
27
|
+
|
28
|
+
## Use
|
data/Rakefile
ADDED
data/bin/yamg
ADDED
data/lib/yamg/version.rb
ADDED
data/lib/yamg.rb
ADDED
@@ -0,0 +1,419 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
require 'rainbow'
|
3
|
+
require 'mini_magick'
|
4
|
+
|
5
|
+
MiniMagick.processor = :gm if ENV['gm']
|
6
|
+
|
7
|
+
#
|
8
|
+
# Yet Another Media Generator
|
9
|
+
#
|
10
|
+
class YAMG
|
11
|
+
attr_accessor :config
|
12
|
+
|
13
|
+
TEMPLATES = {
|
14
|
+
|
15
|
+
#
|
16
|
+
# Android Cordova/Phonegap
|
17
|
+
#
|
18
|
+
android: {
|
19
|
+
# TODO: check if we really need this duplication on android
|
20
|
+
icons: {
|
21
|
+
'res/drawable/icon.png' => 96,
|
22
|
+
'res/drawable-ldpi/icon.png' => 36,
|
23
|
+
'res/drawable-mdpi/icon.png' => 48,
|
24
|
+
'res/drawable-hdpi/icon.png' => 72,
|
25
|
+
'res/drawable-xhdpi/icon.png' => 96,
|
26
|
+
'res/drawable-xxhdpi/icon.png' => 256,
|
27
|
+
'bin/res/drawable/icon.png' => 96,
|
28
|
+
'bin/res/drawable-ldpi/icon.png' => 36,
|
29
|
+
'bin/res/drawable-mdpi/icon.png' => 48,
|
30
|
+
'bin/res/drawable-hdpi/icon.png' => 72,
|
31
|
+
'bin/res/drawable-xhdpi/icon.png' => 96,
|
32
|
+
'ant-build/res/drawable/icon.png' => 96,
|
33
|
+
'ant-build/res/drawable-ldpi/icon.png' => 36,
|
34
|
+
'ant-build/res/drawable-mdpi/icon.png' => 48,
|
35
|
+
'ant-build/res/drawable-hdpi/icon.png' => 72,
|
36
|
+
'ant-build/res/drawable-xhdpi/icon.png' => 96
|
37
|
+
},
|
38
|
+
splash: {
|
39
|
+
'res/drawable-port-ldpi/screen.png' => [200, 320],
|
40
|
+
'res/drawable-port-mdpi/screen.png' => [320, 480],
|
41
|
+
'res/drawable-port-hdpi/screen.png' => [480, 800],
|
42
|
+
'res/drawable-port-xhdpi/screen.png' => [720, 1280],
|
43
|
+
'res/drawable-land-ldpi/screen.png' => [320, 200],
|
44
|
+
'res/drawable-land-mdpi/screen.png' => [480, 320],
|
45
|
+
'res/drawable-land-hdpi/screen.png' => [800, 480],
|
46
|
+
'res/drawable-land-xhdpi/screen.png' => [1280, 720],
|
47
|
+
'bin/res/drawable-port-ldpi/screen.png' => [200, 320],
|
48
|
+
'bin/res/drawable-port-mdpi/screen.png' => [320, 480],
|
49
|
+
'bin/res/drawable-port-hdpi/screen.png' => [480, 800],
|
50
|
+
'bin/res/drawable-port-xhdpi/screen.png' => [720, 1280],
|
51
|
+
'bin/res/drawable-land-ldpi/screen.png' => [320, 200],
|
52
|
+
'bin/res/drawable-land-mdpi/screen.png' => [480, 320],
|
53
|
+
'bin/res/drawable-land-hdpi/screen.png' => [800, 480],
|
54
|
+
'bin/res/drawable-land-xhdpi/screen.png' => [1280, 720],
|
55
|
+
'ant-build/res/drawable-port-ldpi/screen.png' => [200, 320],
|
56
|
+
'ant-build/res/drawable-port-mdpi/screen.png' => [320, 480],
|
57
|
+
'ant-build/res/drawable-port-hdpi/screen.png' => [480, 800],
|
58
|
+
'ant-build/res/drawable-port-xhdpi/screen.png' => [720, 1280],
|
59
|
+
'ant-build/res/drawable-land-ldpi/screen.png' => [320, 200],
|
60
|
+
'ant-build/res/drawable-land-mdpi/screen.png' => [480, 320],
|
61
|
+
'ant-build/res/drawable-land-hdpi/screen.png' => [800, 480],
|
62
|
+
'ant-build/res/drawable-land-xhdpi/screen.png' => [1280, 720]
|
63
|
+
}
|
64
|
+
},
|
65
|
+
|
66
|
+
#
|
67
|
+
# iOS cordova/phonegap
|
68
|
+
#
|
69
|
+
ios: {
|
70
|
+
icons: {
|
71
|
+
'Resources/icons/icon.png' => 57,
|
72
|
+
'Resources/icons/icon@2x.png' => 114,
|
73
|
+
'Resources/icons/icon-40.png' => 40,
|
74
|
+
'Resources/icons/icon-40@2x.png' => 80,
|
75
|
+
'Resources/icons/icon-40@3x.png' => 120,
|
76
|
+
'Resources/icons/icon-50.png' => 50,
|
77
|
+
'Resources/icons/icon-50@2x.png' => 100,
|
78
|
+
'Resources/icons/icon-60.png' => 60,
|
79
|
+
'Resources/icons/icon-60@2x.png' => 120,
|
80
|
+
'Resources/icons/icon-60@3x.png' => 180,
|
81
|
+
'Resources/icons/icon-72.png' => 72,
|
82
|
+
'Resources/icons/icon-72@2x.png' => 144,
|
83
|
+
'Resources/icons/icon-76.png' => 76,
|
84
|
+
'Resources/icons/icon-76@2x.png' => 152,
|
85
|
+
'Resources/icons/icon-120.png' => 120,
|
86
|
+
'Resources/icons/icon-small.png' => 29,
|
87
|
+
'Resources/icons/icon-small@2x.png' => 58,
|
88
|
+
'Resources/icons/icon-small@3x.png' => 87
|
89
|
+
},
|
90
|
+
splash: {
|
91
|
+
'Resources/splash/Default~iphone.png' => [320, 480],
|
92
|
+
'Resources/splash/Default@2x~iphone.png' => [640, 960],
|
93
|
+
'Resources/splash/Default-Landscape@2x~ipad.png' => [2048, 1536],
|
94
|
+
'Resources/splash/Default-Landscape~ipad.png' => [1024, 768],
|
95
|
+
'Resources/splash/Default-Portrait@2x~ipad.png' => [1536, 2048],
|
96
|
+
'Resources/splash/Default-Portrait~ipad.png' => [768, 1024],
|
97
|
+
'Resources/splash/Default-568h@2x~iphone.png' => [640, 1136],
|
98
|
+
'Resources/splash/Default-667h.png' => [750, 1344],
|
99
|
+
'Resources/splash/Default-736h.png' => [1242, 2208],
|
100
|
+
'Resources/splash/Default-Landscape-736h.png' => [2208, 1242]
|
101
|
+
}
|
102
|
+
},
|
103
|
+
|
104
|
+
#
|
105
|
+
# Phonegap www/res/
|
106
|
+
#
|
107
|
+
phonegap: {
|
108
|
+
icon: {
|
109
|
+
'icon/android/icon-36-ldpi.png' => 36,
|
110
|
+
'icon/android/icon-48-mdpi.png' => 48,
|
111
|
+
'icon/android/icon-72-hdpi.png' => 72,
|
112
|
+
'icon/android/icon-96-xhdpi.png' => 96,
|
113
|
+
'icon/blackberry/icon-80.png' => 80,
|
114
|
+
'icon/ios/icon-57.png' => 57,
|
115
|
+
'icon/ios/icon-57-2x.png' => 114,
|
116
|
+
'icon/ios/icon-72.png' => 72,
|
117
|
+
'icon/webos/icon-64.png' => 64,
|
118
|
+
'icon/windows-phone/icon-173-tile.png' => 173,
|
119
|
+
'icon/windows-phone/icon-62-tile.png' => 62,
|
120
|
+
'icon/windows-phone/icon-48.png' => 48
|
121
|
+
},
|
122
|
+
splash: {
|
123
|
+
'screen/android/screen-ldpi-landscape.png' => [200, 320],
|
124
|
+
'screen/android/screen-mdpi-landscape.png' => [320, 480],
|
125
|
+
'screen/android/screen-hdpi-landscape.png' => [480, 800],
|
126
|
+
'screen/android/screen-xhdpi-landscape.png' => [720, 1280],
|
127
|
+
'screen/android/screen-ldpi-portrait.png' => [320, 200],
|
128
|
+
'screen/android/screen-mdpi-portrait.png' => [480, 320],
|
129
|
+
'screen/android/screen-hdpi-portrait.png' => [800, 480],
|
130
|
+
'screen/android/screen-xhdpi-portrait.png' => [1280, 720],
|
131
|
+
'screen/blackberry/screen-225' => [225],
|
132
|
+
'screen/ios/screen-ipad-landscape-2x.png' => [2048, 1536],
|
133
|
+
'screen/ios/screen-ipad-landscape.png' => [1024, 768],
|
134
|
+
'screen/ios/screen-ipad-portrait-2x.png' => [1536, 2048],
|
135
|
+
'screen/ios/screen-ipad-portrait.png' => [768, 1024],
|
136
|
+
'screen/ios/screen-iphone-landscape.png' => [480, 320],
|
137
|
+
'screen/ios/screen-iphone-landscape-2x.png' => [960, 640],
|
138
|
+
'screen/ios/screen-iphone-portrait-2x.png' => [640, 960],
|
139
|
+
'screen/ios/screen-iphone-portrait-568h-2x.png' => [640, 1136],
|
140
|
+
'screen/ios/screen-iphone-portrait.png' => [320, 480],
|
141
|
+
'screen/ios/screen-iDefault~iphone.png' => [320, 480],
|
142
|
+
'screen/ios/screen-iDefault-667h.png' => [750, 1344],
|
143
|
+
'screen/ios/screen-iDefault-736h.png' => [1242, 2208],
|
144
|
+
'screen/ios/screen-iDefault-Landscape-736h.png' => [2208, 1242],
|
145
|
+
'screen/windows-phone/screen-portrait.jpg' => [720, 1280]
|
146
|
+
}
|
147
|
+
},
|
148
|
+
|
149
|
+
#
|
150
|
+
# WWW
|
151
|
+
#
|
152
|
+
web: {
|
153
|
+
icons: {
|
154
|
+
'icon.png' => 256
|
155
|
+
},
|
156
|
+
media: {
|
157
|
+
'media.png' => 256
|
158
|
+
}
|
159
|
+
},
|
160
|
+
|
161
|
+
rails: {
|
162
|
+
icons: {
|
163
|
+
'public/favicon.png' => 16,
|
164
|
+
'public/favicon.ico' => 16,
|
165
|
+
'public/icon.png' => 512,
|
166
|
+
'app/assets/images/icon.png' => 512,
|
167
|
+
'app/assets/images/favicon.png' => 16
|
168
|
+
},
|
169
|
+
media: {
|
170
|
+
'public/logo.png' => 512
|
171
|
+
}
|
172
|
+
},
|
173
|
+
|
174
|
+
twitter: {
|
175
|
+
icons: {
|
176
|
+
'icon.png' => 256
|
177
|
+
}
|
178
|
+
},
|
179
|
+
|
180
|
+
#
|
181
|
+
# Play Store
|
182
|
+
#
|
183
|
+
google: {
|
184
|
+
icons: {
|
185
|
+
'icon.png' => 512,
|
186
|
+
'icon1024.png' => 1024, # [1024, 500]
|
187
|
+
'180.png' => 180, # 180, 120
|
188
|
+
},
|
189
|
+
splash: {
|
190
|
+
'splash.png' => [1024, 768]
|
191
|
+
}
|
192
|
+
},
|
193
|
+
|
194
|
+
#
|
195
|
+
# App Store
|
196
|
+
#
|
197
|
+
apple: {
|
198
|
+
icons: {
|
199
|
+
'icon.png' => 1024,
|
200
|
+
'icon16.png' => 16
|
201
|
+
},
|
202
|
+
splash: {
|
203
|
+
'splash.png' => [1024, 768]
|
204
|
+
}
|
205
|
+
},
|
206
|
+
|
207
|
+
facebook: {
|
208
|
+
icons: {
|
209
|
+
'icon.png' => 1024,
|
210
|
+
'icon16.png' => 16
|
211
|
+
},
|
212
|
+
splash: {
|
213
|
+
'splash.png' => [1024, 768]
|
214
|
+
}
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
def initialize
|
219
|
+
load_config
|
220
|
+
end
|
221
|
+
|
222
|
+
def load_config
|
223
|
+
self.config = YAML.load_file('./.yamg.yml').freeze
|
224
|
+
rescue Errno::ENOENT
|
225
|
+
puts 'Create config!'
|
226
|
+
exit 1
|
227
|
+
end
|
228
|
+
|
229
|
+
def setup_for(opts)
|
230
|
+
case opts
|
231
|
+
when Hash then opts
|
232
|
+
when String then { 'path' => opts }
|
233
|
+
when TrueClass then { 'path' => './media' }
|
234
|
+
else fail
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
#
|
239
|
+
# Writes image to disk
|
240
|
+
#
|
241
|
+
def write_out(img, path)
|
242
|
+
img.format File.extname(path)
|
243
|
+
FileUtils.mkdir_p File.dirname(path)
|
244
|
+
img.write(path)
|
245
|
+
rescue Errno::ENOENT
|
246
|
+
puts
|
247
|
+
puts Rainbow("Path not found '#{path}'").red
|
248
|
+
exit 1
|
249
|
+
end
|
250
|
+
|
251
|
+
def compile_work(scope, opts)
|
252
|
+
puts Rainbow("Working on #{scope}'").blue
|
253
|
+
setup = setup_for(opts)
|
254
|
+
|
255
|
+
if (t = TEMPLATES[scope.to_sym])
|
256
|
+
Thread.new do # 200% speed up with 8 cores
|
257
|
+
icon_work(t[:icons], setup)
|
258
|
+
splash_work(t[:splash], setup) if t[:splash]
|
259
|
+
end
|
260
|
+
else
|
261
|
+
puts 'Custom job!'
|
262
|
+
end
|
263
|
+
end
|
264
|
+
|
265
|
+
def compile(scope = nil)
|
266
|
+
time = Time.now
|
267
|
+
works = config['compile']
|
268
|
+
works.select! { |w| w =~ scope } if scope
|
269
|
+
works.each { |out, opts| compile_work(out, opts) }
|
270
|
+
Thread.list.reject { |t| t == Thread.current }.each(&:join)
|
271
|
+
puts Rainbow("Done compile #{Time.now - time}").red
|
272
|
+
end
|
273
|
+
|
274
|
+
#
|
275
|
+
#
|
276
|
+
# ICONS
|
277
|
+
#
|
278
|
+
#
|
279
|
+
def load_icons(path)
|
280
|
+
return [path] unless File.extname(path).empty?
|
281
|
+
Dir["#{path}/*.png"].map { |f| File.basename(f) }
|
282
|
+
end
|
283
|
+
|
284
|
+
def find_closest_gte_icon(size, icons)
|
285
|
+
return icons.max_by(&:to_i) if icons.map(&:to_i).max < size
|
286
|
+
icons.min_by do |f|
|
287
|
+
# n = x.match(/\d+/).to_s.to_i
|
288
|
+
n = f.to_i
|
289
|
+
size > n ? Float::INFINITY : n
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def icon_work(files, setup)
|
294
|
+
path = setup['icon'] || config['icon']['path']
|
295
|
+
rounded = setup['rounded'] || config['icon']['rounded']
|
296
|
+
icons = load_icons(path)
|
297
|
+
puts Rainbow("Starting in #{path} with #{icons} | #{setup}").blue
|
298
|
+
files.each do |file, size|
|
299
|
+
from = File.join(path, find_closest_gte_icon(size, icons))
|
300
|
+
to = File.join(setup['path'], file)
|
301
|
+
puts "#{File.basename from} -> #{to} (#{size}px)"
|
302
|
+
image = MiniMagick::Image.open(from)
|
303
|
+
image.resize size # "NxN"
|
304
|
+
image = round(image) if rounded
|
305
|
+
write_out(image, to)
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
# https://gist.github.com/artemave/c20e7450af866f5e7735
|
310
|
+
def round(img, r = 14)
|
311
|
+
size = img.dimensions.join(',')
|
312
|
+
r = img.dimensions.max / r
|
313
|
+
radius = [r, r].join(',')
|
314
|
+
|
315
|
+
mask = MiniMagick::Image.open(img.path)
|
316
|
+
mask.format 'png'
|
317
|
+
|
318
|
+
mask.combine_options do |m|
|
319
|
+
m.alpha 'transparent'
|
320
|
+
m.background 'none'
|
321
|
+
m.draw "roundrectangle 0,0,#{size},#{radius}"
|
322
|
+
end
|
323
|
+
|
324
|
+
overlay = ::MiniMagick::Image.open img.path
|
325
|
+
overlay.format 'png'
|
326
|
+
|
327
|
+
overlay.combine_options do |o|
|
328
|
+
o.alpha 'transparent'
|
329
|
+
o.background 'none'
|
330
|
+
o.draw "roundrectangle 0,0,#{size},#{radius}"
|
331
|
+
end
|
332
|
+
|
333
|
+
masked = img.composite(mask, 'png') do |i|
|
334
|
+
i.alpha 'set'
|
335
|
+
i.compose 'DstIn'
|
336
|
+
end
|
337
|
+
|
338
|
+
masked.composite(overlay, 'png') do |i|
|
339
|
+
i.compose 'Over'
|
340
|
+
end
|
341
|
+
masked
|
342
|
+
|
343
|
+
# convert
|
344
|
+
# -size 512x512 xc:none
|
345
|
+
# -draw "roundrectangle 0,0,512,512,55,55" mask.png
|
346
|
+
# convert icon.png
|
347
|
+
# -matte mask.png
|
348
|
+
# -compose DstIn
|
349
|
+
# -composite picture_with_rounded_corners.png
|
350
|
+
end
|
351
|
+
|
352
|
+
#
|
353
|
+
#
|
354
|
+
# SPLASH
|
355
|
+
#
|
356
|
+
#
|
357
|
+
def splash_center(path, size, bg = config['splash']['background'])
|
358
|
+
icon_size = size.max / 4
|
359
|
+
image = MiniMagick::Image.open(path)
|
360
|
+
image.resize icon_size if image.dimensions.max >= icon_size
|
361
|
+
image.background bg if bg
|
362
|
+
image.combine_options do |o|
|
363
|
+
o.gravity 'center'
|
364
|
+
o.extent size.join('x') # "WxH"
|
365
|
+
end
|
366
|
+
end
|
367
|
+
|
368
|
+
def splash_composite(base, icons)
|
369
|
+
max = base.dimensions.min / 9
|
370
|
+
icons.reduce(base) do |img, over|
|
371
|
+
oimg = MiniMagick::Image.open(File.join(config['splash']['path'], over))
|
372
|
+
oimg.resize(max) if oimg.dimensions.max >= max
|
373
|
+
img.composite(oimg) do |o|
|
374
|
+
o.compose 'Over'
|
375
|
+
o.gravity File.basename(over, '.*')
|
376
|
+
o.geometry '+40%+40%'
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
381
|
+
def splash_work(screens, setup)
|
382
|
+
path = config['splash']['path']
|
383
|
+
icons = load_icons(path)
|
384
|
+
center = icons.find { |i| i =~ /center/ }
|
385
|
+
icons.delete(center)
|
386
|
+
|
387
|
+
puts Rainbow("Starting splashes | #{setup}").blue
|
388
|
+
screens.each do |file, size|
|
389
|
+
to = File.join(setup['path'], file)
|
390
|
+
image = splash_center(File.join(path, center), size)
|
391
|
+
write_out(splash_composite(image, icons), to)
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
def screenshot
|
396
|
+
puts 'SS'
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
# },
|
401
|
+
# "customImages": [
|
402
|
+
# {
|
403
|
+
# "width": 120,
|
404
|
+
# "height": 120,
|
405
|
+
# "path": "../Media/custom",
|
406
|
+
# "filename": "outputFilename.png",
|
407
|
+
# "source": {
|
408
|
+
# "filename": "image.png",
|
409
|
+
# "background": "fff6d5"
|
410
|
+
# }
|
411
|
+
# }
|
412
|
+
# ],
|
413
|
+
# "screenshots": [
|
414
|
+
# {
|
415
|
+
# "url": "http://notabe.com",
|
416
|
+
# "name": "homepage"
|
417
|
+
# }
|
418
|
+
# ]
|
419
|
+
# }
|
data/yamg.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'yamg/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'yamg'
|
7
|
+
s.version = YAMG::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Marcos Piccinini']
|
10
|
+
s.email = ['nofxx@github.com']
|
11
|
+
s.homepage = 'http://github.com/nofxx/yamg'
|
12
|
+
s.summary = 'Yet another media generator'
|
13
|
+
s.description = 'Provides all the media for your projects'
|
14
|
+
s.license = 'MIT'
|
15
|
+
|
16
|
+
s.executables = ['yamg']
|
17
|
+
s.default_executable = 'yamg'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.require_paths = ['lib']
|
22
|
+
|
23
|
+
s.add_dependency 'mini_magick'
|
24
|
+
s.add_dependency 'rainbow'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yamg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Marcos Piccinini
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-26 00:00:00.000000000 Z
|
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: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rainbow
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Provides all the media for your projects
|
42
|
+
email:
|
43
|
+
- nofxx@github.com
|
44
|
+
executables:
|
45
|
+
- yamg
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".coveralls.yml"
|
50
|
+
- ".gitignore"
|
51
|
+
- ".hound.yml"
|
52
|
+
- ".travis.yml"
|
53
|
+
- Gemfile
|
54
|
+
- Guardfile
|
55
|
+
- MIT-LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- bin/yamg
|
59
|
+
- lib/yamg.rb
|
60
|
+
- lib/yamg/version.rb
|
61
|
+
- yamg.gemspec
|
62
|
+
homepage: http://github.com/nofxx/yamg
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.4.7
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Yet another media generator
|
86
|
+
test_files: []
|