forked from Ninjanetic/ios2android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ios2android
executable file
·86 lines (67 loc) · 2.73 KB
/
ios2android
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/bash
# ios2android - a simple script to port iOS retina images to the appropriate Android density buckets
#
# For more information: https://github.com/Ninjanetic/ios2android
# The MIT License (MIT)
# Copyright (c) 2013 Ninjanetic Design Inc.
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Requires Imagemagick
# To install on Mac: brew install imagemagick
# Floating point number functions from http://www.linuxjournal.com/content/floating-point-math-bash
#####################################################################
# Default scale used by float functions.
float_scale=2
#####################################################################
# Evaluate a floating point number expression.
function float_eval()
{
local stat=0
local result=0.0
if [[ $# -gt 0 ]]; then
result=$(echo "scale=$float_scale; $*" | bc -q 2>/dev/null)
stat=$?
if [[ $stat -eq 0 && -z "$result" ]]; then stat=1; fi
fi
echo $result
return $stat
}
#####################################################################
# Process images.
if [ -z "$PROJECT_PATH" ]; then
echo "Set env variable PROJECT_PATH to dump files"
exit 1
fi
path="${PROJECT_PATH}/src/main/res"
for ii in *.jpg *.png; do
if [ -f $ii ];
then
x=${ii/@3x./.}
if [[ ${x} =~ -568h ]]; then
x=${x/-568h./.}
fi
x=${x//-/_}
if [[ ${x} =~ ^[0-9] ]]; then
x="img_${x}"
fi
x=`echo $x | tr "[:upper:]" "[:lower:]"`
echo $ii
convert -resize 33.3% $ii $path/drawable-mdpi/$x
convert -resize 50% $ii $path/drawable-hdpi/$x
convert -resize 66.6% $ii $path/drawable-xhdpi/$x
convert -resize 100% $ii $path/drawable-xxhdpi/$x
fi
done