assets - How to add pngs from svg to XCode project with a shell script? -
is there way update assets of project tools/scripts external xcode?
i draw icons in inkscape. i've discovered simple script this:
#!/bin/sh tail=$(basename "$1") name="${tail%.*}" /applications/inkscape.app/contents/resources/bin/inkscape -d 135 --export-png ${name}@3x.png ${name}.svg /applications/inkscape.app/contents/resources/bin/inkscape -d 90 --export-png ${name}@2x.png ${name}.svg /applications/inkscape.app/contents/resources/bin/inkscape -d 45 --export-png ${name}.png ${name}.svg
i can auto generate 3 different pngs appropriate name @ resolutions. easier point-n-click interactive route.
what love do, add end of script automatically inject 3 pngs assets of xcode project. don't know how/where xcode manages those.
full script
the full script, derived @matthias 's answer (my svg directory sits sibling project directory)...
#!/bin/sh tail=$(basename "$1") name="${tail%.*}" projectname=myvalve target=../${projectname}/images.xcassets/${name}.imageset mkdir -p ${target} /applications/inkscape.app/contents/resources/bin/inkscape -d 135 --export-png ${target}/${name}@3x.png ${name}.svg /applications/inkscape.app/contents/resources/bin/inkscape -d 90 --export-png ${target}/${name}@2x.png ${name}.svg /applications/inkscape.app/contents/resources/bin/inkscape -d 45 --export-png ${target}/${name}.png ${name}.svg cat > ${target}/contents.json << __eof__ { "images" : [ { "idiom" : "universal", "scale" : "1x", "filename" : "${name}.png" }, { "idiom" : "universal", "scale" : "2x", "filename" : "${name}@2x.png" }, { "idiom" : "universal", "scale" : "3x", "filename" : "${name}@3x.png" } ], "info" : { "version" : 1, "author" : "xcode" } } __eof__
i don't have copy & paste solution, can provide starting point.
i added 3 images , file structure looks quite easy. file diff in git:
new file: objctest/images.xcassets/image123.imageset/contents.json new file: objctest/images.xcassets/image123.imageset/image123.png new file: objctest/images.xcassets/image123.imageset/image123@2x.png new file: objctest/images.xcassets/image123.imageset/image123@3x.png
so don't have touch xml stuff project.
, contents.json isn't complicated either:
{ "images" : [ { "idiom" : "universal", "scale" : "1x", "filename" : "image123.png" }, { "idiom" : "universal", "scale" : "2x", "filename" : "image123@2x.png" }, { "idiom" : "universal", "scale" : "3x", "filename" : "image123@3x.png" } ], "info" : { "version" : 1, "author" : "xcode" } }
xcode 6 has couple of options can set in asset editor. if need those, change them , see how contents.json changes.
Comments
Post a Comment