calavicci 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.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/calavicci +6 -0
- data/bin/convert +0 -0
- data/bin/drawable_convert.py +84 -0
- data/calavicci.gemspec +23 -0
- data/lib/calavicci/version.rb +3 -0
- data/lib/calavicci.rb +42 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Todd Grooms
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Calavicci
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'calavicci'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install calavicci
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/calavicci
ADDED
data/bin/convert
ADDED
Binary file
|
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
|
3
|
+
import sys
|
4
|
+
import argparse
|
5
|
+
import os
|
6
|
+
import subprocess
|
7
|
+
import re
|
8
|
+
|
9
|
+
'''
|
10
|
+
A simple script to create lower-resolution Android drawables from higher-resolution ones.
|
11
|
+
|
12
|
+
For example, given a batch of -xhdpi images, you can generate -hdpi and -mdpi images.
|
13
|
+
|
14
|
+
This makes it possible to only export highest-resolution artwork from image authoring tools, and
|
15
|
+
automate the rest.
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
|
19
|
+
drawable_convert.py -d res/drawable-mdpi -d res/drawable-hdpi res/drawable-xhdpi-v14/select*.png
|
20
|
+
|
21
|
+
... will take select*.png from xhdpi and place versions into mdpi and hdpi folders.
|
22
|
+
|
23
|
+
Correct resize ratios are computed based on resource directory names.
|
24
|
+
|
25
|
+
Actual scaling is done by ImageMagick's convert command.
|
26
|
+
'''
|
27
|
+
|
28
|
+
class Converter:
|
29
|
+
def __init__(self, dstList):
|
30
|
+
print u'Dst list: {0}'.format(dstList)
|
31
|
+
self.mDstList = dstList
|
32
|
+
|
33
|
+
def convert(self, src):
|
34
|
+
for dstpath in self.mDstList:
|
35
|
+
(srcpath, srcname) = os.path.split(src)
|
36
|
+
dst = os.path.join(dstpath, srcname)
|
37
|
+
self.convertOne(src, dst)
|
38
|
+
|
39
|
+
def convertOne(self, src, dst):
|
40
|
+
print u'\n*****\n{0} to {1}\n*****\n'.format(src, dst)
|
41
|
+
'''
|
42
|
+
Determine relative density
|
43
|
+
'''
|
44
|
+
srcDpi = self.getDpi(src)
|
45
|
+
dstDpi = self.getDpi(dst)
|
46
|
+
|
47
|
+
if srcDpi < dstDpi:
|
48
|
+
print u'NOT converting from {0}dpi to {1}dpi'.format(srcDpi, dstDpi)
|
49
|
+
else:
|
50
|
+
factor = dstDpi*100/srcDpi
|
51
|
+
print u'Converting from {0}dpi to {1}dpi, {2}%'.format(srcDpi, dstDpi, factor)
|
52
|
+
cmd = u'./bin/convert -verbose "{0}" -scale "{2}%" "{1}"'.format(src, dst, factor)
|
53
|
+
out = subprocess.Popen(['sh', '-c', cmd])
|
54
|
+
output,error = out.communicate()
|
55
|
+
|
56
|
+
def getDpi(self, f):
|
57
|
+
p = os.path.dirname(f)
|
58
|
+
if re.match('.*drawable.*\\-ldpi.*', p):
|
59
|
+
return 120
|
60
|
+
elif re.match('.*drawable.*\\-mdpi.*', p):
|
61
|
+
return 160
|
62
|
+
elif re.match('.*drawable.*\\-hdpi.*', p):
|
63
|
+
return 240
|
64
|
+
elif re.match('.*drawable.*\\-xhdpi.*', p):
|
65
|
+
return 320
|
66
|
+
else:
|
67
|
+
raise ValueError(u'Cannot determine densitiy for {0}'.format(p))
|
68
|
+
|
69
|
+
if __name__ == "__main__":
|
70
|
+
'''
|
71
|
+
Parse command line arguments
|
72
|
+
'''
|
73
|
+
parser = argparse.ArgumentParser(description='Converts drawable resources in Android applications')
|
74
|
+
parser.add_argument('-d', dest='DST', action='append', required=True, help='destination directory')
|
75
|
+
parser.add_argument('src', nargs='+', help='files to convert (one or more)')
|
76
|
+
args = parser.parse_args()
|
77
|
+
|
78
|
+
cv = Converter(args.DST)
|
79
|
+
suffix = '.9.png'
|
80
|
+
for src in args.src:
|
81
|
+
if src.endswith(suffix):
|
82
|
+
print u'Skipping 9-patch: {0}'.format(src)
|
83
|
+
else:
|
84
|
+
cv.convert(src)
|
data/calavicci.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'calavicci/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "calavicci"
|
8
|
+
spec.version = Calavicci::VERSION
|
9
|
+
spec.authors = ["Todd Grooms"]
|
10
|
+
spec.email = ["todd.grooms@gmail.com"]
|
11
|
+
spec.description = "The gist for the drawable_convert.py script can be found here: https://gist.github.com/kmansoft/2771791"
|
12
|
+
spec.summary = "Wrapper to execute a drawable converter to convert xhdpi Android resources to lower resolution resources."
|
13
|
+
spec.homepage = "http://github.com/metova/calavicci"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = ["calavicci", "convert", "drawable_convert.py"]
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/calavicci.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require "calavicci/version"
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Calavicci
|
5
|
+
class DrawableConverter
|
6
|
+
def scale
|
7
|
+
puts 'Scaling...'
|
8
|
+
|
9
|
+
options = {}
|
10
|
+
OptionParser.new do |opts|
|
11
|
+
opts.banner = "Usage: calavicci [options]"
|
12
|
+
|
13
|
+
opts.on('-o', '--output DIRECTORY', 'Output Directory') do |opt|
|
14
|
+
options[:output_directory] = [] unless options[:output_directory]
|
15
|
+
options[:output_directory] << opt
|
16
|
+
end
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
if ARGV[0].nil?
|
20
|
+
raise ArgumentError, 'No input directory given!'
|
21
|
+
end
|
22
|
+
|
23
|
+
input_directory = ARGV[0].chomp('/')
|
24
|
+
arguments = ""
|
25
|
+
if options[:output_directory].nil? || options[:output_directory].length == 0
|
26
|
+
# Guess the mdpi and hdpi directories based on the given input directory
|
27
|
+
arguments += "-d #{input_directory}/../drawable-mdpi "
|
28
|
+
arguments += "-d #{input_directory}/../drawable-hdpi "
|
29
|
+
else
|
30
|
+
options[:output_directory].each do |output_directory|
|
31
|
+
arguments += "-d #{output_directory} "
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
input_directory += "/*.png"
|
36
|
+
python_command = "python bin/drawable_convert.py #{arguments}#{input_directory}"
|
37
|
+
|
38
|
+
puts "Executing #{python_command}"
|
39
|
+
result = exec(python_command)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: calavicci
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Todd Grooms
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-11-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: ! 'The gist for the drawable_convert.py script can be found here: https://gist.github.com/kmansoft/2771791'
|
47
|
+
email:
|
48
|
+
- todd.grooms@gmail.com
|
49
|
+
executables:
|
50
|
+
- calavicci
|
51
|
+
- convert
|
52
|
+
- drawable_convert.py
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- .gitignore
|
57
|
+
- Gemfile
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.md
|
60
|
+
- Rakefile
|
61
|
+
- calavicci.gemspec
|
62
|
+
- lib/calavicci.rb
|
63
|
+
- lib/calavicci/version.rb
|
64
|
+
- bin/calavicci
|
65
|
+
- bin/convert
|
66
|
+
- bin/drawable_convert.py
|
67
|
+
homepage: http://github.com/metova/calavicci
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.25
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Wrapper to execute a drawable converter to convert xhdpi Android resources
|
92
|
+
to lower resolution resources.
|
93
|
+
test_files: []
|