XCUtils 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dcd1f85c0b54c113211610a5dce1c47688977d89
4
+ data.tar.gz: c48fe82723ee0d41cc1dd8ac7d3687e734767c89
5
+ SHA512:
6
+ metadata.gz: 2f7580bb23a6d349765658f1d50814d6bd20b79da452a8ce86b8b228584fca8132559d05b38083cbe077e1c69058a7519a8b934283d68a308dbe9306bd9444c4
7
+ data.tar.gz: 82ef5082eb22083810f427f2defe54177f45779a4ab194367d9c0ae76d282084eef5896181522f4b61b37c06306e399826cfcc1d0446e7171134a5749c9e5a93
data/bin/xcatlasify ADDED
@@ -0,0 +1,37 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "XCUtils/version"
4
+ require 'rubygems'
5
+
6
+ require "thor"
7
+ require_relative "../lib/XCUtils/xcutils_resizer"
8
+
9
+ class XCAtlasify < Thor
10
+
11
+ desc "resize [src-dir, tgt-dir]", "Resize *.@2x~ipad named images and move em into XCodes atlases."
12
+ long_desc <<-LONGDESC
13
+ This is a little helper to resize @2x~ipad artwork to all required sizes using rmagick.
14
+ \x5On top, the output will be formatted to suit XCodes requirements for sprite atlases.
15
+ \x5Images will be resized carefully by first extending images to be dividable by 4 and then generating smaller half and quarter resolutions.
16
+ LONGDESC
17
+ def resize(src, tgt)
18
+ validate_support
19
+ ARGV.shift
20
+ XCUtils::XCUtilsResizer.start
21
+ end
22
+
23
+ desc "sort", "This is a little helper to sort a directory containing normal, @2x, ~ipad, @2x~ipad artwork into 4 atlases."
24
+ def sort
25
+ validate_support
26
+ ARGV.shift
27
+ XCUtils::XCUtilsSorter.start
28
+ end
29
+
30
+ private
31
+ def validate_support
32
+ # check if the action is valid...
33
+ end
34
+
35
+ end
36
+
37
+ XCAtlasify.start
@@ -0,0 +1,3 @@
1
+ module XCUtils
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,67 @@
1
+ require "thor"
2
+ require 'RMagick'
3
+ require 'fileutils'
4
+ require 'debugger'
5
+
6
+ module XCUtils
7
+ class XCUtilsResizer < Thor::Group
8
+ include Thor::Actions
9
+
10
+ argument :source
11
+ argument :target
12
+
13
+ def create_output_directory
14
+ say_status "create_output_directory", nil
15
+ name = File.basename target
16
+ Dir.mkdir(target) unless Dir.exists?(target)
17
+ Dir.mkdir(File.join(target,"#{name}.atlas")) unless Dir.exists?(File.join(target,"#{name}.atlas"))
18
+ Dir.mkdir(File.join(target,"#{name}@2x.atlas")) unless Dir.exists?(File.join(target,"#{name}@2x.atlas"))
19
+ Dir.mkdir(File.join(target,"#{name}~ipad.atlas")) unless Dir.exists?(File.join(target,"#{name}~ipad.atlas"))
20
+ Dir.mkdir(File.join(target,"#{name}@2x~ipad.atlas")) unless Dir.exists?(File.join(target,"#{name}@2x~ipad.atlas"))
21
+ end
22
+
23
+ def write_rename_images_to_dir
24
+ name = File.basename target
25
+ Dir.foreach(source) do |f|
26
+ next if f == "." || f == ".." || f == ".DS_Store"
27
+
28
+ if f.include?("@2x") && f.include?("~ipad")
29
+
30
+ fn = f.gsub("@2x","").gsub("~ipad","")
31
+
32
+ # load image
33
+ img = Magick::Image.read(File.join(source,f)).first
34
+ img.background_color = "none"
35
+
36
+ # adjust image size so it's devitable by 4
37
+ width = img.columns
38
+ height = img.rows
39
+
40
+ nWidth = width%4 == 0 ? width : (width + 4 - width%4)
41
+ nHeight = height%4 == 0 ? height : (height + 4 - height%4)
42
+
43
+ img = img.extent(nWidth, nHeight)
44
+
45
+ # create ipad retina version
46
+ say_status "create ipad retina version", "#{name}@2x~ipad.atlas"
47
+ img.write(File.join(target,"#{name}@2x~ipad.atlas",fn))
48
+
49
+ # create ipad non retina version
50
+ say_status "create ipad non retina version", "#{name}@~ipad.atlas"
51
+ img.minify!
52
+ img.write(File.join(target,"#{name}~ipad.atlas",fn))
53
+
54
+ # create iphone retina version - identical to ipad non retina version
55
+ say_status "create iphone retina version - identical to ipad non retina version", "#{name}@2x.atlas"
56
+ img.write(File.join(target,"#{name}@2x.atlas",fn))
57
+
58
+ # create iphone non retina version
59
+ say_status "create iphone non retina version", "#{name}.atlas"
60
+ img.minify!
61
+ img.write(File.join(target,"#{name}.atlas",fn))
62
+ end
63
+ end
64
+ end
65
+
66
+ end
67
+ end
@@ -0,0 +1,58 @@
1
+ require "thor"
2
+ require 'fileutils'
3
+ require 'debugger'
4
+
5
+ module XCUtils
6
+ class XCUtilsSorter < Thor::Group
7
+ include Thor::Actions
8
+
9
+ argument :source
10
+ argument :target
11
+
12
+ def create_output_directory
13
+ say_status "create_output_directory", nil
14
+ name = File.basename target
15
+ Dir.mkdir(target) unless Dir.exists?(target)
16
+ Dir.mkdir(File.join(target,"#{name}.atlas")) unless Dir.exists?(File.join(target,"#{name}.atlas"))
17
+ Dir.mkdir(File.join(target,"#{name}@2x.atlas")) unless Dir.exists?(File.join(target,"#{name}@2x.atlas"))
18
+ Dir.mkdir(File.join(target,"#{name}~ipad.atlas")) unless Dir.exists?(File.join(target,"#{name}~ipad.atlas"))
19
+ Dir.mkdir(File.join(target,"#{name}@2x~ipad.atlas")) unless Dir.exists?(File.join(target,"#{name}@2x~ipad.atlas"))
20
+ end
21
+
22
+ def sort_directory
23
+ say_status "sort directory"
24
+ i = 0
25
+ b = [0,0,0,0]
26
+
27
+ # move files
28
+ Dir.foreach(source) do |f|
29
+ next if f == "." || f == ".." || f == ".DS_Store"
30
+
31
+ p fn = f
32
+
33
+ if (!f.include?("@2x") && !f.include?("~ipad"))
34
+ FileUtils.mv(File.join(source,f),File.join(target,"#{name}.atlas",fn))
35
+ i = i+1
36
+ b[0] = b[0]+1
37
+ elsif (f.include?("@2x") && !f.include?("~ipad"))
38
+ FileUtils.mv(File.join(source,f),File.join(target,"#{name}@2x.atlas",fn.gsub("@2x","")))
39
+ i = i+1
40
+ b[1] = b[1]+1
41
+ elsif (!f.include?("@2x") && f.include?("~ipad"))
42
+ FileUtils.mv(File.join(source,f),File.join(target,"#{name}~ipad.atlas",fn.gsub("~ipad","")))
43
+ i = i+1
44
+ b[2] = b[2]+1
45
+ elsif (f.include?("@2x") && f.include?("~ipad"))
46
+ FileUtils.mv(File.join(source,f),File.join(target,"#{name}@2x~ipad.atlas",fn.gsub("@2x~ipad","")))
47
+ i = i+1
48
+ b[3] = b[3]+1
49
+ end
50
+ end
51
+
52
+ # some checking
53
+ p "total number of files moved: #{i}"
54
+ p "! Issue detected: not same amount of files in each atlas (#{b})" unless b[0] == b[1] && b[1] == b[2] && b[2] == b[3]
55
+ end
56
+
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: XCUtils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Benjamin Müller
8
+ - Manolis Pahlke
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-05-27 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.3'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.3'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: thor
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rmagick
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ~>
61
+ - !ruby/object:Gem::Version
62
+ version: 2.13.2
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.13.2
70
+ - !ruby/object:Gem::Dependency
71
+ name: fileutils
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - '>='
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: debugger
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: |-
99
+ This is a little helper to resize @2x~ipad artwork to all required sizes using rmagick.
100
+ \x5On top, the output will be formatted to suit XCodes requirements for sprite atlases.
101
+ \x5Images will be resized carefully by first extending images to be dividable by 4 and then generating smaller half and quarter resolutions.
102
+ email:
103
+ - benjamin@urbn.de
104
+ - manolis@urbn.de
105
+ executables:
106
+ - xcatlasify
107
+ extensions: []
108
+ extra_rdoc_files: []
109
+ files:
110
+ - bin/xcatlasify
111
+ - lib/XCUtils/version.rb
112
+ - lib/XCUtils/xcutils_resizer.rb
113
+ - lib/XCUtils/xcutils_sorter.rb
114
+ homepage: https://github.com/elchbenny/XCUtils
115
+ licenses:
116
+ - MIT
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - '>='
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.2.2
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Resize *.@2x~ipad named images and move em into XCodes atlases.
138
+ test_files: []