Last active
October 27, 2015 07:07
-
-
Save shikajiro/e686f023764950f43cac to your computer and use it in GitHub Desktop.
Android用のpng画像生成スクリプト。svg画像をmdpi, hdpi, xhdpi, xxhdpi, xxxhdpi毎のpng画像に変換する。要Inkscape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Copyright 2015 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
/** | |
* svgの画像を各dpiのフォルダにpngに変換する。 | |
* カレントディレクトリのみ対応。 | |
* inkscapeを利用しているため、別途インストールが必須。 | |
* $ groovy svg2png.groovy | |
*/ | |
/*メッセージ出力用*/ | |
SUCESS = (""+(char)27+"[32msuccess") | |
NG = (""+(char)27+"[31mNG") | |
COLOR_CODE_DEFAULT = (""+(char)27+"[39m") | |
//出力するフォルダとdpiの組み合わせ | |
dpis = ["mdpi":90, "hdpi":135, "xhdpi":180, "xxhdpi":270, "xxxhdpi":360] | |
//カレントディレクトリに各dpiフォルダを作成する | |
src = new File(".") | |
/* | |
* inkscapeによる変換処理をdpiフォルダ分行う。 | |
* svgからpngしか変換は行わない。 | |
*/ | |
dpis.each { dir, dpi -> | |
dpiDir = new File(src, "drawable-"+dir) | |
if(!dpiDir.exists()){ | |
dpiDir.mkdir() | |
} | |
src.eachFile{ file -> | |
if(!file.name.endsWith('.svg')) return | |
target = file.getAbsoluteFile().path | |
output = dpiDir.getCanonicalPath() + "/" + file.getName().replace(".svg", ".png") | |
command = String.format("inkscape %s -e %s -d %d", target, output, dpi) | |
print command | |
result = command.execute().waitFor() | |
println " => " + (result==0?SUCESS:NG) + COLOR_CODE_DEFAULT | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment