yamg 0.3.1 → 0.3.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: 59cec81256da8c78e11ce4dd4946ced256ee6c27
4
- data.tar.gz: 944c9d0189b94dcc96a89b2498ae2c1cb300e7ac
3
+ metadata.gz: bf2b7296e3006b737d2a5f5780b534c13eab885a
4
+ data.tar.gz: 7b6ea2ab7b6a39df88a2785fa49fc8351bea4fc3
5
5
  SHA512:
6
- metadata.gz: f4a2f9d61123b1be043e1c9db9a9126971263d81865394d3eca9e8fef947d2914eb9187eaf89889291ce189ff1f0f01be128cd0a05990467eca07a881fa0563d
7
- data.tar.gz: 4e3b8e53bd1d03a3fdeab6e242f4f2575dcb16394ceacad4b6173af61f7ccafe0fb934dc180a6a5020570d041b6d46ae2ca532788435100a76b2eda7a355be94
6
+ metadata.gz: dfdeb113584059c2eeaad5c1c3cb188d0522106d3d34277f69cb79c018c3d9277a6274d6581dab266b040bf26ebcb16592c208ac05e45a0770eb646a3675c87f
7
+ data.tar.gz: 2c9032970481ce85899328fdfe3dd2e75084031ec07b8c274f13d93d1f84a09ab91b235f59785fedc9f933674be329269dbf4bef5cbd7da9ad171d111b05dd91
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # YAMG
2
2
 
3
- ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
3
+ ┏ ┓
4
4
 
5
- _____ _____ _____ ______ _______ _____
5
+ _____ _____ _____ ______ _______ _____
6
6
  |\ \ / /| ___|\ \ | \/ \ ___|\ \
7
7
  | \ \ / / | / /\ \ / /\ \ / /\ \
8
8
  | \____\/ / /| | | | / /\ / /\ || | |____|
@@ -10,11 +10,11 @@
10
10
  \|___/ / / | .--. || | \|_|/ / / || | | |
11
11
  / / / | | | || | | | || | |_, |
12
12
  /____/ / |____| |____||\____\ |____| /|\ ___\___/ /|
13
- |` | / | | | || | | | | / | | /____ / |
14
- |_____|/ |____| |____| \|____| |____|/ \|___| | /
15
- \|____|/
13
+ | | / | | | || | | | | / | | /____ / |
14
+ |____|/ |____| |____| \|____| |____|/ \|___| | /
15
+ |____|/
16
16
 
17
- ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
17
+ ┗ ┛
18
18
 
19
19
 
20
20
  [![Gem Version](https://badge.fury.io/rb/yamg.png)](http://badge.fury.io/rb/yamg)
@@ -51,18 +51,45 @@ OSX
51
51
 
52
52
  ## Use
53
53
 
54
- yamg
54
+ First time
55
+
56
+ yamg init
55
57
 
56
58
  A `.yamg.yml` will be created on the folder.
59
+ From now on to recompile everything when needed:
60
+
61
+ yamg
62
+
63
+ An example folder `/art` of a project:
64
+
65
+
66
+ ```
67
+ art
68
+ ├── icons
69
+ │   ├── icon16.png
70
+ │   ├── icon32.png
71
+ │   └── icon512.svg
72
+ ├── media
73
+ │   └── logo.svg
74
+ └─── splash
75
+    ├── center.png
76
+    ├── north.png
77
+    └── southeast.png
78
+
79
+ ```
57
80
 
81
+ From the `.yamg.yml` you may configure differents source paths.
82
+ Also configure every export location you need (check #Support)
58
83
 
59
- ### Icons
84
+ ## Icons
60
85
 
61
86
  Your main icon(s) may be SVG or PNG. Or both:
62
- SVG is always the best choice except really small (16x16, 32x32)
63
- icons: there you can show your pixel art skills to the world.
87
+ SVG is always the best choice, it will be rasterized and not resized.
88
+ Except will be with really small (16x16, 32x32, 64x64@2x) icons:
89
+ A canvas for you to bring joy to the world with your pixel art skills.
64
90
 
65
- #### PNG
91
+
92
+ ### PNG
66
93
 
67
94
  Multiple sizes:
68
95
  Just save your files with the size in pixels first, example:
@@ -70,27 +97,28 @@ In the 'icons/' folder: '16-icon.png', '32-icon.png', '512-icon.png'.
70
97
  YAMG will choose the best size for the case, and don't touch
71
98
  the icon if sizes are a match.
72
99
 
73
- It's ok to (or if you) have only one icon, make it >512px.
100
+ It's ok to (or if you) have only one png icon, make it >512px.
74
101
 
75
- #### SVG
102
+ ### SVG
76
103
 
77
104
  You may still use best size match: Just have you folder:
78
- '16-icon.svg', '256-icon.svg', problably not much more:
105
+ '16-icon.svg', '256-icon.svg', and problably not many other sizes:
79
106
  The SVG will be rasterized in the correct size needed.
80
107
 
81
108
 
82
- ### Splash
109
+ ## Splash
83
110
 
84
111
  Up to 9 images may be placed in a splash.
112
+ It's not patch 9, think gravity: images will be pulled towards.
85
113
  Note: The center splash image must be named 'center'.
86
114
 
87
- #### Gravity
115
+ ### Gravity
88
116
 
89
117
  Just save you files with the names: 'north', 'northeast', 'south'...
90
118
  Gravity will put em in the correct place, with a lil padding.
91
119
 
92
120
 
93
- ### Media
121
+ ## Media
94
122
 
95
123
  Addional media.
96
124
  There's also media generator for app stores.
@@ -107,8 +135,23 @@ Custom screenshots:
107
135
  scroll: 100 # Optional
108
136
 
109
137
 
138
+ ## Config file
139
+
140
+ Explain yamg.yml:
141
+
142
+ ```
143
+ icon:
144
+ path:
145
+ round:
146
+ ```
110
147
 
111
- ### Support
148
+ Custom location:
149
+
150
+ some-project:
151
+ icon: [32, 64, 128]
152
+
153
+
154
+ ## Support
112
155
 
113
156
  * iOS Project
114
157
  * OSX Project
@@ -126,12 +169,12 @@ Custom screenshots:
126
169
 
127
170
  ## Notes
128
171
 
129
- #### Media
172
+ ### Media
130
173
 
131
174
  Media is a logo, icon + name.
132
175
 
133
176
 
134
- #### Phonegap or Cordova
177
+ ### Phonegap or Cordova
135
178
 
136
179
  You may generate assets for both, but the difference is:
137
180
  Phonegap (`www/res`) assets are used only on Phonegap Build.
data/lib/yamg/cli.rb CHANGED
@@ -54,20 +54,15 @@ module YAMG
54
54
  YAMG.info("Splash #{size.join('x')}px #{setup['path']}#{s}", :black)
55
55
  end
56
56
 
57
- def compile_work(template, opts)
58
- setup = setup_for(opts)
59
-
60
- if (task = YAMG::TEMPLATES[template])
61
- %w(icon splash media).each do |key|
62
- next unless (work = task[key])
63
- work.each do |i, d|
64
- #Thread.new do # 200% speed up with 8 cores
65
- send(:"compile_#{key}", i, d, setup)
66
- #end
57
+ def compile_work(job, opts)
58
+ task = YAMG::TEMPLATES[job] || (works[job] && works[job]['export'])
59
+ %w(icon splash media).each do |key|
60
+ next unless (work = task[key])
61
+ work.each do |asset, size|
62
+ Thread.new do # 500% speed up with 8 cores
63
+ send(:"compile_#{key}", asset, size, setup_for(opts))
67
64
  end
68
65
  end
69
- else
70
- # puts 'Custom job!'
71
66
  end
72
67
  end
73
68
 
data/lib/yamg/icon.rb CHANGED
@@ -4,16 +4,25 @@ module YAMG
4
4
  #
5
5
  #
6
6
  class Icon
7
- attr_accessor :src, :size, :dpi, :rounded, :icons
7
+ attr_accessor :src, :size, :dpi, :rounded, :radius, :icons, :img
8
8
 
9
- def initialize(src, size, rounded = false)
9
+ #
10
+ # Icon
11
+ #
12
+ # Icon.new(src, size, rounded).image
13
+ # Image class
14
+ # Icon.new(src, size, rounded).image('.path.ext')
15
+ # Export image
16
+ #
17
+ def initialize(src, size, rounded = false, radius = 9)
10
18
  fail if src.nil? || src.empty?
11
19
  @src = src
12
20
  @size = size
13
21
  @rounded = rounded
14
22
  @icons = YAMG.load_images(src)
15
23
  YAMG.puts_and_exit("No sources in '#{src}'") if icons.empty?
16
- @path = File.join(src, find_closest_gte_icon)
24
+ @choosen = File.join(src, find_closest_gte_icon)
25
+ @radius = radius
17
26
  @dpi = 90
18
27
  end
19
28
  alias_method :rounded?, :rounded
@@ -27,18 +36,12 @@ module YAMG
27
36
  end
28
37
  end
29
38
 
30
- def image(out)
31
- if File.extname(@path) =~ /svg/
32
- pixels = dpi ? "-d #{dpi} -p #{dpi}" : nil
33
- args = "#{pixels} -w #{size} -h #{size} -f png"
34
- YAMG.run_rsvg(@path, out, args)
35
- img = MiniMagick::Image.open(out)
36
- else
37
- img = MiniMagick::Image.open(@path)
38
- img.resize size # "NxN"
39
- write_out(img, out)
40
- end
41
- write_out(round(img), out) if rounded?
39
+ def radius
40
+ Array.new(2, size / @radius).join(',')
41
+ end
42
+
43
+ def dimensions
44
+ img.dimensions.join(',')
42
45
  end
43
46
 
44
47
  #
@@ -51,18 +54,14 @@ module YAMG
51
54
  # -compose DstIn
52
55
  # -composite picture_with_rounded_corners.png
53
56
  # https://gist.github.com/artemave/c20e7450af866f5e7735
54
- def round(img, r = 14)
55
- size = img.dimensions.join(',')
56
- r = img.dimensions.max / r
57
- radius = [r, r].join(',')
58
-
57
+ def round(r = 14)
59
58
  mask = MiniMagick::Image.open(img.path)
60
59
  mask.format 'png'
61
60
 
62
61
  mask.combine_options do |m|
63
62
  m.alpha 'transparent'
64
63
  m.background 'none'
65
- m.draw "roundrectangle 0,0,#{size},#{radius}"
64
+ m.draw "roundrectangle 0,0,#{dimensions},#{radius}"
66
65
  end
67
66
 
68
67
  overlay = ::MiniMagick::Image.open img.path
@@ -71,7 +70,7 @@ module YAMG
71
70
  overlay.combine_options do |o|
72
71
  o.alpha 'transparent'
73
72
  o.background 'none'
74
- o.draw "roundrectangle 0,0,#{size},#{radius}"
73
+ o.draw "roundrectangle 0,0,#{dimensions},#{radius}"
75
74
  end
76
75
 
77
76
  masked = img.composite(mask, 'png') do |i|
@@ -85,14 +84,30 @@ module YAMG
85
84
  masked
86
85
  end
87
86
 
87
+ def image(out = nil)
88
+ temp = out || "/tmp/#{@choosen.object_id}.png"
89
+ if File.extname(@choosen) =~ /svg/
90
+ pixels = dpi ? "-d #{dpi} -p #{dpi}" : nil
91
+ args = "#{pixels} -w #{size} -h #{size} -f png"
92
+ YAMG.run_rsvg(@choosen, temp, args)
93
+ @img = MiniMagick::Image.open(temp)
94
+ else
95
+ @img = MiniMagick::Image.open(@choosen)
96
+ @img.resize size # "NxN"
97
+ end
98
+ @img = round if rounded?
99
+ write_out(out)
100
+ end
101
+
88
102
  #
89
103
  # Writes image to disk
90
104
  #
91
- def write_out(img, out)
92
- FileUtils.mkdir_p File.dirname(out)
93
- img.write(out)
105
+ def write_out(path = nil)
106
+ return img unless path
107
+ FileUtils.mkdir_p File.dirname(path)
108
+ img.write(path)
94
109
  rescue Errno::ENOENT
95
- puts_and_exit("Path not found '#{out}'")
110
+ puts_and_exit("Path not found '#{path}'")
96
111
  end
97
112
  end
98
113
  end
data/lib/yamg/splash.rb CHANGED
@@ -6,6 +6,15 @@ module YAMG
6
6
  class Splash
7
7
  attr_accessor :src, :bg, :size, :assets, :img
8
8
 
9
+ #
10
+ # Splash
11
+ #
12
+ # Splash.new(src, size, rounded).image
13
+ # Image class
14
+ #
15
+ # Icon.new(src, size, rounded).image('.path.ext')
16
+ # Export image
17
+ #
9
18
  def initialize(src, size, background)
10
19
  @src = src
11
20
  @size = size
@@ -26,7 +35,7 @@ module YAMG
26
35
  # Center image
27
36
  #
28
37
  def splash_start
29
- icon_size = size.max / 9
38
+ icon_size = size.min / 5
30
39
  img.resize icon_size if img.dimensions.max >= icon_size
31
40
  img.combine_options do |o|
32
41
  o.gravity 'center'
@@ -58,11 +67,12 @@ module YAMG
58
67
  end
59
68
 
60
69
  #
61
- # Writes image to disk
70
+ # Outputs instance or writes image to disk
62
71
  #
63
- def image(out)
72
+ def image(out = nil)
64
73
  splash_start
65
74
  splash_composite
75
+ return img unless out
66
76
  FileUtils.mkdir_p File.dirname(out)
67
77
  img.write(out)
68
78
  rescue Errno::ENOENT
@@ -5,6 +5,8 @@ raster:
5
5
  'icon64.png': 64
6
6
  'icon128.png': 128
7
7
  'icon256.png': 256
8
+ 'icon512.png': 512
9
+ 'icon1024.png': 1024
8
10
  splash:
9
11
  'splash-port-sm.png': [480, 320]
10
12
  'splash-port-md.png': [1024, 768]
data/lib/yamg/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # :nodoc:
2
2
  module YAMG
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.3'
4
4
  end
data/lib/yamg/yamg.yml CHANGED
@@ -58,6 +58,18 @@ compile:
58
58
  # Compiles to media/facebook
59
59
  facebook: true
60
60
 
61
+ #
62
+ # Creating your own
63
+ #
64
+ # my-proj:
65
+ # path: '../app/www/img'
66
+ # # icon: './another/source' # icon here is source
67
+ # export:
68
+ # icon: # Notice: icon inside export
69
+ # 'icon16.png': 16
70
+ # 'icon64.png': 64
71
+ # 'icon128.png': 128
72
+
61
73
  # Custom icons/splash
62
74
  # Compiles to media/*
63
75
  # custom:
data/lib/yamg.rb CHANGED
@@ -42,6 +42,8 @@ module YAMG
42
42
  def load_images(dir)
43
43
  return [dir] unless File.extname(dir).empty?
44
44
  Dir["#{dir}/*.{svg,png,jpg}"].map { |f| File.basename(f) }
45
+ rescue TypeError
46
+ puts_and_exit("Bad config file path: #{dir}")
45
47
  end
46
48
 
47
49
  def run(comm)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Piccinini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-29 00:00:00.000000000 Z
11
+ date: 2015-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mini_magick