Skip to content

Instantly share code, notes, and snippets.

@zhanghai
Created December 11, 2014 06:27
Show Gist options
  • Save zhanghai/6dddffb9aaf8b529da28 to your computer and use it in GitHub Desktop.
Save zhanghai/6dddffb9aaf8b529da28 to your computer and use it in GitHub Desktop.
Script for generating image assets of different DPIs for Android from SVG source file, using Inkscape.
#!/bin/bash
#
# dpigen.sh: Script for generating image assets of different DPIs for Android from SVG source file, using Inkscape.
#
# Copyright (c) 2014 Zhang Hai <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see
# <http://www.gnu.org/licenses/>.
#
MDPI_SIZE="48"
HDPI_SIZE="72"
XHDPI_SIZE="96"
XXHDPI_SIZE="144"
XXXHDPI_SIZE="192"
MDPI_DIR="drawable-mdpi"
HDPI_DIR="drawable-hdpi"
XHDPI_DIR="drawable-xhdpi"
XXHDPI_DIR="drawable-xxhdpi"
XXXHDPI_DIR="drawable-xxxhdpi"
name=$(basename "$0")
raw=
out=
usage() {
cat <<EOF
Usage: ${name} [OPTIONS]
EOF
}
dpigen() {
mkdir -p "./$1"
inkscape --export-png="./$1/${out}" --export-width="$2" --export-height="$2" "${raw}"
}
main () {
if [[ "$#" -ne 1 ]]; then
usage
exit 1
fi
raw="$1"
out="$(basename -s.svg ${raw}).png"
dpigen "${MDPI_DIR}" "${MDPI_SIZE}"
dpigen "${HDPI_DIR}" "${HDPI_SIZE}"
dpigen "${XHDPI_DIR}" "${XHDPI_SIZE}"
dpigen "${XXHDPI_DIR}" "${XXHDPI_SIZE}"
dpigen "${XXXHDPI_DIR}" "${XXXHDPI_SIZE}"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment