summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-03-13 19:20:42 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2020-03-16 16:16:37 +0000
commit0f2a759b69467f730df0d0055cce82292355ea16 (patch)
treee61a9987a79bedef3d7f0853f751c9c3f111a89c /android
parent25f84f3f38e325537a9973e9bbfe44a66c05c5ac (diff)
downloadmullvadvpn-0f2a759b69467f730df0d0055cce82292355ea16.tar.xz
mullvadvpn-0f2a759b69467f730df0d0055cce82292355ea16.zip
Add script to generate PNG images for Android
Diffstat (limited to 'android')
-rwxr-xr-xandroid/generate-pngs.sh88
1 files changed, 88 insertions, 0 deletions
diff --git a/android/generate-pngs.sh b/android/generate-pngs.sh
new file mode 100755
index 0000000000..59735a24d9
--- /dev/null
+++ b/android/generate-pngs.sh
@@ -0,0 +1,88 @@
+#!/usr/bin/env bash
+
+set -eu
+
+if ! command -v rsvg-convert > /dev/null; then
+ echo >&2 "rsvg-convert (librsvg) is required to run this script"
+ exit 1
+fi
+
+SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+cd "$SCRIPT_DIR"
+
+# The following helper function converts an SVG image into a PNG image for a specific DPI
+#
+# Parameters:
+# 1. Path to source SVG image
+# 2. DPI config, a string with two or three parameters separated by '-'s
+# a. the DPI specification, as the suffix of the output directory (e.g., mdpi, xxhdpi)
+# b. the width of the generated PNG image
+# c. (optional) the height of the generated PNG image, if not specified it is assumed to be the
+# same as the width in order to output a square image
+# 3. (optional) The destination image name, if not specified it is assumed to be the same as the
+# input image name, with any '-'s replaced with '_'s
+# 4. (optional) Destination directory type, either 'drawable' (the default) or 'mipmap'
+#
+# Examples:
+#
+# The following will generate a 50 by 50 image in android/src/main/res/drawable-hdpi/my_image.png
+#
+# convert_image /tmp/my-image.svg hdpi-50
+#
+# The following will generate a 50 by 50 image in android/src/main/res/drawable-mdpi/other_image.png
+#
+# convert_image /tmp/my-other-image.svg mdpi-50 other_image
+#
+# The following will generate a 50 by 25 image in android/src/main/res/mipmap-xxhdpi/my_icon.png
+#
+# convert_image /tmp/my-final-image.svg xxhdpi-50-25 my_icon mipmap
+function convert_image() {
+ if (( $# < 2 )); then
+ echo "Too few arguments passed to 'convert_image'" >&2
+ exit 1
+ fi
+
+ local source_image="$1"
+ local dpi_config="$2"
+
+ if (( $# >= 3 )); then
+ local destination_image="$3"
+ else
+ local destination_image="$(basename "$source_image" .svg | sed -e 's/-/_/g')"
+ fi
+
+ if (( $# >= 4 )); then
+ local destination_dir="$4"
+ else
+ local destination_dir="drawable"
+ fi
+
+ local dpi="$(echo "$dpi_config" | cut -f1 -d'-')"
+ local width="$(echo "$dpi_config" | cut -f2 -d'-')"
+ local height="$(echo "$dpi_config" | cut -f3 -d'-')"
+
+ if [ -z "$height" ]; then
+ local height="$width"
+ fi
+
+ local dpi_dir="./src/main/res/${destination_dir}-${dpi}"
+
+ echo "$source_image -> ($width x $height) ${dpi_dir}/${destination_image}.png"
+ mkdir -p "$dpi_dir"
+ rsvg-convert "$source_image" -w "$width" -h "$height" -o "${dpi_dir}/${destination_image}.png"
+}
+
+# Launcher icon
+for dpi_size in "mdpi-48" "hdpi-72" "xhdpi-96" "xxhdpi-144" "xxxhdpi-192"; do
+ convert_image "../dist-assets/icon.svg" "$dpi_size" "ic_launcher" "mipmap"
+done
+
+# Logo used in some GUI areas
+for dpi_size in "mdpi-50" "hdpi-75" "xhdpi-100" "xxhdpi-150" "xxxhdpi-200"; do
+ convert_image "../dist-assets/icon.svg" "$dpi_size" "logo_icon"
+done
+
+# Large logo used in the launch screen
+for dpi_size in "mdpi-120" "hdpi-180" "xhdpi-240" "xxhdpi-360" "xxxhdpi-480"; do
+ convert_image "../dist-assets/icon.svg" "$dpi_size" "launch_logo"
+done