Skip to content

Instantly share code, notes, and snippets.

@AtkinsSJ
Last active August 29, 2015 14:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save AtkinsSJ/7ec948ce87390fd4029e to your computer and use it in GitHub Desktop.
Windows Batch File for generating drawable PNGs from SVG files using Inkscape.

This makes a few assumptions:

  • That Inkscape is in your PATH
  • That there is an svg directory with your SVG files
  • That all the files need to be exported at the same size
  • You might need to change the target path if your project is set up differently, but it's made for the default in IntelliJ, so Android Studio should match.

License

Copyright (c) 2015 Samuel Atkins

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.

setlocal EnableDelayedExpansion
@echo off
set sizes[m]=24
set sizes[h]=36
set sizes[xh]=48
set sizes[xxh]=72
set sizes[xxxh]=96
for %%f in (.\svg\*.svg) do (
for %%r in (m h xh xxh xxxh) do (
set size=!sizes[%%r]!
set src=%%f
set name=!src:~6,-4!
@echo on
inkscape -f !src! -w !size! -h !size! -e .\app\src\main\res\drawable-%%rdpi\!name!.png
@echo off
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment