acbaker 0.0.3 → 0.0.5

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: 4812fc0a537d4b5ec3c4f82fee692e6329302940
4
- data.tar.gz: 8c72e59d353439629ef45da3d64e4aa030b5f2ac
3
+ metadata.gz: e0da3aebf60075ce0d77dbcdda8353ef87d099dd
4
+ data.tar.gz: d545f2520a8bb8ff17ac7ea78be66a0a32252d60
5
5
  SHA512:
6
- metadata.gz: 7612ecedd2a2ee2a657049708ce2b53909b8f1c69350a934a91f64546d39a3fd840f70146de6c65cafa28c60ef99b2a3b51ce60f3b82c3cffe5c3d3420edc65a
7
- data.tar.gz: b817e65daff69034d4b25156b5b3224e44c7b29710071235dcd1866d57f188efa9e0c4fe7113e636e9f055febe78059a7b9171f2a11c97a5a8b709fe0028d944
6
+ metadata.gz: a7b744fbf7d7b0728bbd9a0f5f3521f9c588f35110a0b7d480d9491deb94b876ff2463e4fe9e9a7a51e85121f071bbeffc433e7f2f352e156bd1637766cb4cf5
7
+ data.tar.gz: 7ab1d19be2e6bf202b417b72edd40e041ee479b105f9de7beefe0779598bc85e37b438ff1f0fa14e58dcf051fb55a7071df903dafbf9191ed36abea3f3490842
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  .DS_Store
2
2
  tmp/*
3
- acbaker-*.gem
3
+ acbaker-*.gem
4
+ /input/*
5
+ /output/*
data/README.md CHANGED
@@ -20,6 +20,12 @@ USAGE
20
20
  CHANGELOG
21
21
  ---------
22
22
 
23
+ * **0.0.5**
24
+ * Add dynamic sizing option
25
+
26
+ * **0.0.4**
27
+ * Add crop strategy and gravity support
28
+
23
29
  * **0.0.3**
24
30
  * Allow json config without fixed size
25
31
 
data/acbaker.gemspec CHANGED
@@ -16,6 +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
20
  s.add_development_dependency "rake", '~> 10.0'
20
21
  s.files = `git ls-files`.split("\n")
21
22
  s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'rmagick'
2
3
 
3
4
  module Acbaker
4
5
  class AssetPack
@@ -17,7 +18,7 @@ module Acbaker
17
18
  end
18
19
 
19
20
  def defaults
20
- {json: false}
21
+ {json: false, gravity: 'Center', strategy: 'cover'}
21
22
  end
22
23
 
23
24
  def process(source_image_file, target_directory, &block)
@@ -26,11 +27,15 @@ module Acbaker
26
27
  json_output_file = File.join(target_directory, "Contents.json")
27
28
 
28
29
  # Loop through images
29
- @json_data['images'].each_with_index do |image_spec, index|
30
-
30
+ @json_data['images'].each_with_index.map do |image_spec, index|
31
+
32
+ image_size_present = image_spec['size']
33
+ image_magick = Magick::Image::read(source_image_file)[0]
34
+ image_spec['size'] = "#{image_magick.columns.to_s}x#{image_magick.rows.to_s}" unless image_size_present
35
+
31
36
  # Get size
32
37
  scale = image_spec['scale'].gsub('x', '').to_i
33
- if image_spec['size']
38
+ if image_size_present
34
39
  (width_str, height_str) = image_spec['size'].split('x')
35
40
  width = width_str.to_i * scale
36
41
  height = height_str.to_i * scale
@@ -81,10 +86,14 @@ module Acbaker
81
86
  end
82
87
 
83
88
  # Generate image
84
- if image_spec['size']
85
- cmd = "convert #{source_image_file} -resize #{width}x#{height}^ -gravity Center -crop #{width}x#{height}+0+0 +repage #{target_directory}/#{filename}"
89
+ if image_size_present
90
+ if @options[:strategy] == 'contain'
91
+ cmd = "convert #{source_image_file} -resize #{width}x -size #{width}x#{height} xc:#FFFFFF +swap -gravity #{@options[:gravity]} -composite #{target_directory}/#{filename}"
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
86
95
  else
87
- cmd = "convert #{source_image_file} -gravity Center +repage #{target_directory}/#{filename}"
96
+ cmd = "convert #{source_image_file} -gravity #{@options[:gravity]} +repage #{target_directory}/#{filename}"
88
97
  end
89
98
  system(cmd)
90
99
 
@@ -95,7 +104,7 @@ module Acbaker
95
104
  image_spec['filename'] = filename
96
105
 
97
106
  end
98
-
107
+
99
108
  # Save Contents.json
100
109
  File.open(json_output_file,"w") do |f|
101
110
  f.write(JSON.pretty_generate(@json_data))
@@ -4,6 +4,8 @@ command :'pack' do |c|
4
4
  c.description = "The type will be autodetected by filename, and can be overwritten using the --type option"
5
5
  c.option '--type STRING', String, 'Specify asset pack type'
6
6
  c.option '--json STRING', String, 'Specify custom json file path'
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 (cover, contain)'
7
9
  c.option '--force', String, 'Delete and recreate output directory (careful!)'
8
10
  global_option '--force'
9
11
 
@@ -14,6 +16,8 @@ command :'pack' do |c|
14
16
  @output_directory = args[1]
15
17
  @type = options.type
16
18
  @json = options.json
19
+ @gravity = options.gravity
20
+ @strategy = options.strategy
17
21
  @force = options.force
18
22
 
19
23
  # Validate
@@ -21,11 +25,16 @@ command :'pack' do |c|
21
25
  validate_image!
22
26
  validate_json!
23
27
  validate_type!
28
+ validate_gravity!
29
+ validate_strategy!
30
+
24
31
  validate_output_directory!
25
32
 
26
33
  # Initialize packer
27
34
  asset_pack = Acbaker::AssetPack.new(@type, {
28
- json: JSON.parse(File.open(@json).read)
35
+ json: JSON.parse(File.open(@json).read),
36
+ gravity: @gravity,
37
+ strategy: @strategy
29
38
  })
30
39
 
31
40
  # Pack assets
@@ -79,9 +88,23 @@ command :'pack' do |c|
79
88
  end
80
89
 
81
90
  abort("error: Could not detect asset type.") if not @type
82
-
83
91
  end
84
92
 
93
+ def validate_gravity!
94
+ if not @gravity
95
+ @gravity = "Center"
96
+ end
97
+ abort("error: Invalid gravity specified.") if not ["NorthWest", "North", "NorthEast", "West", "Center", "East", "SouthWest", "South", "SouthEast"].include?(@gravity)
98
+ end
99
+
100
+ def validate_strategy!
101
+ if not @strategy
102
+ @strategy = "cover"
103
+ end
104
+ abort("error: Invalid strategy specified.") if not ["cover", "contain"].include?(@strategy)
105
+ end
106
+
107
+
85
108
  def validate_json!
86
109
  if @json
87
110
  abort("error: JSON file not found.") if not File.exist?(@json) or not File.file?(@json)
@@ -1,3 +1,3 @@
1
1
  module Acbaker
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.5"
3
3
  end
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.3
4
+ version: 0.0.5
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-01-22 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rmagick
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '2.13'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '2.13'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -100,3 +114,4 @@ signing_key:
100
114
  specification_version: 4
101
115
  summary: Convert any source images into xcode asset catalogs.
102
116
  test_files: []
117
+ has_rdoc: