acbaker 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/acbaker.gemspec +1 -1
- data/lib/acbaker/asset_pack.rb +17 -11
- data/lib/acbaker/commands/pack.rb +17 -3
- data/lib/acbaker/processors/base.rb +18 -0
- data/lib/acbaker/processors/center.rb +42 -0
- data/lib/acbaker/processors/contain.rb +30 -0
- data/lib/acbaker/processors/cover.rb +30 -0
- data/lib/acbaker/processors.rb +5 -0
- data/lib/acbaker/version.rb +1 -1
- data/lib/acbaker.rb +1 -0
- data/test/assets/AppIcon.png +0 -0
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d47f4083dd69b97d8e22b739639fd13d85a833f
|
4
|
+
data.tar.gz: 40cc181909e9ebcd6fbdf24bff73d3b2e5e4cfae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c7e66e084a2085e49e00fbfffe567f7149bf7130a232b7129f5c234e7ab4530fb124e0047024ed3f8b80294ee40b240e0e231f36b5af27e538d6604fa538734
|
7
|
+
data.tar.gz: 9f2edbc654a1effbe76f73b9e80e6b04c710a4303440d5a88a9e688d23ade03028ae4bfaa01f36f94008c9b0cbec58db92e950fda793dbeef88a140ae0c68905
|
data/README.md
CHANGED
@@ -20,6 +20,10 @@ USAGE
|
|
20
20
|
CHANGELOG
|
21
21
|
---------
|
22
22
|
|
23
|
+
* **0.0.6**
|
24
|
+
* Implemented processors (advanced image manipulations)
|
25
|
+
* Added "center" strategy (align image in center with relative or absolute width constraints)
|
26
|
+
|
23
27
|
* **0.0.5**
|
24
28
|
* Add dynamic sizing option
|
25
29
|
|
data/acbaker.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
s.required_rubygems_version = '>= 1.3.6'
|
17
17
|
s.add_dependency "commander", '~> 4.1'
|
18
18
|
s.add_dependency 'json', '~> 1.8'
|
19
|
-
s.add_dependency 'rmagick', '~> 2.13'
|
19
|
+
s.add_dependency 'rmagick', '~> 2.13', '>= 2.13.4'
|
20
20
|
s.add_development_dependency "rake", '~> 10.0'
|
21
21
|
s.files = `git ls-files`.split("\n")
|
22
22
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
data/lib/acbaker/asset_pack.rb
CHANGED
@@ -3,10 +3,11 @@ require 'rmagick'
|
|
3
3
|
|
4
4
|
module Acbaker
|
5
5
|
class AssetPack
|
6
|
-
attr_reader :type, :images
|
6
|
+
attr_reader :type, :images, :processors
|
7
7
|
|
8
8
|
def initialize(type, options={})
|
9
9
|
@type = type
|
10
|
+
@processors = []
|
10
11
|
if options[:json]
|
11
12
|
@json_data = options[:json]
|
12
13
|
else
|
@@ -18,7 +19,7 @@ module Acbaker
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def defaults
|
21
|
-
{json: false, gravity: 'Center', strategy: '
|
22
|
+
{json: false, gravity: 'Center', strategy: 'Cover'}
|
22
23
|
end
|
23
24
|
|
24
25
|
def process(source_image_file, target_directory, &block)
|
@@ -26,6 +27,15 @@ module Acbaker
|
|
26
27
|
# Define variables
|
27
28
|
json_output_file = File.join(target_directory, "Contents.json")
|
28
29
|
|
30
|
+
# Get processors
|
31
|
+
if @json_data['processors'] and @json_data['processors'].length
|
32
|
+
@json_data['processors'].each do |processor_spec|
|
33
|
+
@processors.push(Object.const_get(processor_spec['type']).new(self, processor_spec['config']))
|
34
|
+
end
|
35
|
+
else
|
36
|
+
@processors = [Object.const_get("Acbaker::Processors::#{@options[:strategy]}").new(self)]
|
37
|
+
end
|
38
|
+
|
29
39
|
# Loop through images
|
30
40
|
@json_data['images'].each_with_index.map do |image_spec, index|
|
31
41
|
|
@@ -86,16 +96,11 @@ module Acbaker
|
|
86
96
|
end
|
87
97
|
|
88
98
|
# Generate image
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
else
|
93
|
-
cmd = "convert #{source_image_file} -resize #{width}x#{height}^ -gravity #{@options[:gravity]} -crop #{width}x#{height}+0+0 +repage #{target_directory}/#{filename}"
|
94
|
-
end
|
95
|
-
else
|
96
|
-
cmd = "convert #{source_image_file} -gravity #{@options[:gravity]} +repage #{target_directory}/#{filename}"
|
99
|
+
image = Magick::ImageList.new(source_image_file)
|
100
|
+
@processors.each do |processor|
|
101
|
+
image = processor.run(image, image_spec, width, height)
|
97
102
|
end
|
98
|
-
|
103
|
+
image.write("#{target_directory}/#{filename}")
|
99
104
|
|
100
105
|
# Trigger Callback proc
|
101
106
|
block.call("#{target_directory}/#{filename}", index+1) if not block.nil?
|
@@ -106,6 +111,7 @@ module Acbaker
|
|
106
111
|
end
|
107
112
|
|
108
113
|
# Save Contents.json
|
114
|
+
@json_data.delete('processors')
|
109
115
|
File.open(json_output_file,"w") do |f|
|
110
116
|
f.write(JSON.pretty_generate(@json_data))
|
111
117
|
end
|
@@ -5,7 +5,7 @@ command :'pack' do |c|
|
|
5
5
|
c.option '--type STRING', String, 'Specify asset pack type'
|
6
6
|
c.option '--json STRING', String, 'Specify custom json file path'
|
7
7
|
c.option '--gravity STRING', String, 'Specify gravity (NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast)'
|
8
|
-
c.option '--strategy STRING', String, 'Specify strategy (
|
8
|
+
c.option '--strategy STRING', String, 'Specify strategy (Cover, Contain, Center)'
|
9
9
|
c.option '--force', String, 'Delete and recreate output directory (careful!)'
|
10
10
|
global_option '--force'
|
11
11
|
|
@@ -87,6 +87,14 @@ command :'pack' do |c|
|
|
87
87
|
}[token]
|
88
88
|
end
|
89
89
|
|
90
|
+
# Fill json
|
91
|
+
if @type and not @json
|
92
|
+
if File.file?("lib/acbaker/config/#{@type}.json")
|
93
|
+
@json = "lib/acbaker/config/#{@type}.json"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
abort "error: no JSON configuration found" if not @json
|
90
98
|
abort("error: Could not detect asset type.") if not @type
|
91
99
|
end
|
92
100
|
|
@@ -99,9 +107,15 @@ command :'pack' do |c|
|
|
99
107
|
|
100
108
|
def validate_strategy!
|
101
109
|
if not @strategy
|
102
|
-
@strategy = "
|
110
|
+
@strategy = "Cover"
|
111
|
+
end
|
112
|
+
|
113
|
+
# try to instantiate strategy class
|
114
|
+
begin
|
115
|
+
Object.const_get("Acbaker::Processors::#{@strategy}")
|
116
|
+
rescue Exception => e
|
117
|
+
abort("error: Invalid strategy specified.")
|
103
118
|
end
|
104
|
-
abort("error: Invalid strategy specified.") if not ["cover", "contain"].include?(@strategy)
|
105
119
|
end
|
106
120
|
|
107
121
|
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Acbaker
|
2
|
+
module Processors
|
3
|
+
class Base
|
4
|
+
attr_accessor :asset_pack, :options
|
5
|
+
@@defaults = {}
|
6
|
+
|
7
|
+
def initialize(asset_pack, options={})
|
8
|
+
@asset_pack = asset_pack
|
9
|
+
@options = options ? @@defaults.merge(options) : @@defaults
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(image, image_spec, width=nil, height=nil)
|
13
|
+
throw "Acbaker::Processors::Base should be extended"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Acbaker
|
2
|
+
module Processors
|
3
|
+
class Center < Base
|
4
|
+
@@defaults = {"max-width" => "50%", "background-color" => "#FFFFFF", "gravity" => "Center"}
|
5
|
+
|
6
|
+
def run(image, image_spec, width=nil, height=nil)
|
7
|
+
transform_width = width.to_f
|
8
|
+
transform_height = height.to_f
|
9
|
+
target_ratio = transform_width / transform_height
|
10
|
+
image_ratio = image.columns / image.rows
|
11
|
+
|
12
|
+
# calculate dimensions
|
13
|
+
if @options['max-width']
|
14
|
+
if @options['max-width'][-1] == "%"
|
15
|
+
rel_width = (@options['max-width'][0..-2].to_f / 100)
|
16
|
+
transform_width = transform_width * rel_width
|
17
|
+
else
|
18
|
+
transform_width = @options['max-width'].to_f
|
19
|
+
end
|
20
|
+
transform_height = transform_width * image_ratio
|
21
|
+
end
|
22
|
+
|
23
|
+
# resize image
|
24
|
+
image.resize!(transform_width.to_i, transform_height.to_i)
|
25
|
+
|
26
|
+
# create canvas
|
27
|
+
canvas = Magick::Image.new(width, height)
|
28
|
+
if @options['background-color'] == :transparent
|
29
|
+
canvas = canvas.matte_floodfill(1, 1)
|
30
|
+
else
|
31
|
+
canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
|
32
|
+
end
|
33
|
+
|
34
|
+
# place image
|
35
|
+
image = canvas.composite(image, Magick::CenterGravity, Magick::OverCompositeOp)
|
36
|
+
|
37
|
+
image
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Acbaker
|
2
|
+
module Processors
|
3
|
+
class Contain < Base
|
4
|
+
@@defaults = {"background-color" => "#FFFFFF", "gravity" => "Center"}
|
5
|
+
|
6
|
+
def run(image, image_spec, width=nil, height=nil)
|
7
|
+
# resize image
|
8
|
+
image.change_geometry("#{width}x") do |px, py, i|
|
9
|
+
image.resize!(px, py)
|
10
|
+
end
|
11
|
+
|
12
|
+
# crop image
|
13
|
+
canvas = Magick::Image.new(width, height)
|
14
|
+
if @options['background-color'] == :transparent
|
15
|
+
canvas = canvas.matte_floodfill(1, 1)
|
16
|
+
else
|
17
|
+
canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
|
18
|
+
end
|
19
|
+
|
20
|
+
# place image
|
21
|
+
gravity_string = "Magick::#{@options['gravity']}Gravity"
|
22
|
+
gravity = Object.const_get(gravity_string)
|
23
|
+
image = canvas.composite(image, gravity, Magick::OverCompositeOp)
|
24
|
+
|
25
|
+
image
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Acbaker
|
2
|
+
module Processors
|
3
|
+
class Cover < Base
|
4
|
+
@@defaults = {"background-color" => "#FFFFFF", "gravity" => "Center"}
|
5
|
+
|
6
|
+
def run(image, image_spec, width=nil, height=nil)
|
7
|
+
# resize image
|
8
|
+
image.change_geometry("#{width}x#{height}^") do |px, py, i|
|
9
|
+
image.resize!(px, py)
|
10
|
+
end
|
11
|
+
|
12
|
+
# crop image
|
13
|
+
canvas = Magick::Image.new(width, height)
|
14
|
+
if @options['background-color'] == :transparent
|
15
|
+
canvas = canvas.matte_floodfill(1, 1)
|
16
|
+
else
|
17
|
+
canvas = canvas.color_floodfill(1, 1, Magick::Pixel.from_color(@options['background-color']))
|
18
|
+
end
|
19
|
+
|
20
|
+
# place image
|
21
|
+
gravity_string = "Magick::#{@options['gravity']}Gravity"
|
22
|
+
gravity = Object.const_get(gravity_string)
|
23
|
+
image = canvas.composite(image, gravity, Magick::OverCompositeOp)
|
24
|
+
|
25
|
+
image
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/acbaker/version.rb
CHANGED
data/lib/acbaker.rb
CHANGED
data/test/assets/AppIcon.png
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acbaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Strebitzer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -45,6 +45,9 @@ dependencies:
|
|
45
45
|
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '2.13'
|
48
|
+
- - '>='
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 2.13.4
|
48
51
|
type: :runtime
|
49
52
|
prerelease: false
|
50
53
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -52,6 +55,9 @@ dependencies:
|
|
52
55
|
- - ~>
|
53
56
|
- !ruby/object:Gem::Version
|
54
57
|
version: '2.13'
|
58
|
+
- - '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 2.13.4
|
55
61
|
- !ruby/object:Gem::Dependency
|
56
62
|
name: rake
|
57
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,6 +91,11 @@ files:
|
|
85
91
|
- lib/acbaker/commands/pack.rb
|
86
92
|
- lib/acbaker/config/AppIcon.json
|
87
93
|
- lib/acbaker/config/LaunchImage.json
|
94
|
+
- lib/acbaker/processors.rb
|
95
|
+
- lib/acbaker/processors/base.rb
|
96
|
+
- lib/acbaker/processors/center.rb
|
97
|
+
- lib/acbaker/processors/contain.rb
|
98
|
+
- lib/acbaker/processors/cover.rb
|
88
99
|
- lib/acbaker/version.rb
|
89
100
|
- test/assets/AppIcon.png
|
90
101
|
- test/assets/LaunchImage.png
|