From c92f3b3017978428382a979d7c1fcdd77747964c Mon Sep 17 00:00:00 2001 From: matei tm Date: Mon, 12 Nov 2018 14:20:58 +0200 Subject: [PATCH 1/4] Update README.md with install path on Windows. --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2320ed3..f6e0cfc 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,12 @@ This Inkscape extension exports all selected items in different densities. The e Install -------- -Download `android_export.inx` and `android_export.py` and copy both files to your `$HOME/.config/inkscape/extensions` folder. A restart of Inkscape is required. +Download `android_export.inx` and `android_export.py`. Depending on OS, copy both files to your extensions folder: + +* Linux - `$HOME/.config/inkscape/extensions` +* Windows - `%APPDATA%\inkscape\extensions` + +A restart of Inkscape is required. Usage -------- From 9652c03c6f28573e623618df4e2660ba4b262466 Mon Sep 17 00:00:00 2001 From: matei tm Date: Thu, 15 Nov 2018 02:10:12 +0200 Subject: [PATCH 2/4] Updating for Android and iOS support --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f6e0cfc..540b7ef 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -inkscape-android-export +inkscape-mobile-export ======== This Inkscape extension exports all selected items in different densities. The exported PNGs will be named by their ID in the SVG. @@ -6,7 +6,7 @@ This Inkscape extension exports all selected items in different densities. The e Install -------- -Download `android_export.inx` and `android_export.py`. Depending on OS, copy both files to your extensions folder: +Download `android_export.inx`,`android_export.py`,`ios_export.inx`,`ios_export.py`. Depending on OS, copy both files to your extensions folder: * Linux - `$HOME/.config/inkscape/extensions` * Windows - `%APPDATA%\inkscape\extensions` @@ -17,7 +17,9 @@ Usage -------- * Select at least one item to export -* Select `Extensions -> Export -> Android Export…` +* According your needs choose: + 1. Android: Select `Extensions -> Export -> Android Export…` + 2. iOS: Select `Extensions -> Export -> iOS Export…` * Customize the settings according to your needs License From 3f7dce6fa64b1dbec1059f3d69958b4d33ef57ca Mon Sep 17 00:00:00 2001 From: Mircea MATEI Date: Thu, 15 Nov 2018 02:13:47 +0200 Subject: [PATCH 3/4] Fixing resolutions --- android_export.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/android_export.py b/android_export.py index 643f3a6..9fe61c2 100755 --- a/android_export.py +++ b/android_export.py @@ -148,12 +148,12 @@ def add_density_option(self, name, dpi): parser.add_option("--transparent-background", action="store", type="boolstr", help="Transparent background") group = DensityGroup(parser, "Select which densities to export") -group.add_density_option("ldpi", 67.5) -group.add_density_option("mdpi", 90) -group.add_density_option("hdpi", 135) -group.add_density_option("xhdpi", 180) -group.add_density_option("xxhdpi", 270) -group.add_density_option("xxxhdpi", 360) +group.add_density_option("ldpi", 72) +group.add_density_option("mdpi", 96) +group.add_density_option("hdpi", 144) +group.add_density_option("xhdpi", 192) +group.add_density_option("xxhdpi", 288) +group.add_density_option("xxxhdpi", 384) parser.add_option_group(group) parser.add_option("--strip", action="store", type="boolstr", help="Use ImageMagick to reduce the image size") From 1832624e9e2a187377853253821e93bd916be30d Mon Sep 17 00:00:00 2001 From: Mircea MATEI Date: Thu, 15 Nov 2018 02:42:34 +0200 Subject: [PATCH 4/4] Added iOS files reworked from https://github.com/HassanAzzam/inkscape-android-export with changes required by Xamarin --- ios_export.inx | 35 ++++++++++++ ios_export.py | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 179 insertions(+) create mode 100644 ios_export.inx create mode 100644 ios_export.py diff --git a/ios_export.inx b/ios_export.inx new file mode 100644 index 0000000..1e632a1 --- /dev/null +++ b/ios_export.inx @@ -0,0 +1,35 @@ + + + <_name>iOS Export + de.cbecker.ios_export + + ios_export.py + + + + <_param name="title" type="description">Exports all currently selected items in different densities. The exported PNGs will be named by their ID in the SVG, so make sure that all items have reasonable IDs. + + + <_param name="title" type="description">Exports the entire page in different densities. + + + + + + true + true + true + false + true + + + all + + + + + + + diff --git a/ios_export.py b/ios_export.py new file mode 100644 index 0000000..883fbbd --- /dev/null +++ b/ios_export.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python + +# ***** BEGIN APACHE LICENSE BLOCK ***** +# +# Copyright 2013 Christian Becker +# +# 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. +# +# ***** END APACHE LICENCE BLOCK ***** + +import optparse +import os +import subprocess +import sys +from copy import copy +try: + from subprocess import DEVNULL +except ImportError: + DEVNULL = open(os.devnull, 'w') + +def checkForPath(command): + return 0 == subprocess.call([ + command, "--version" + ], stdout=DEVNULL, stderr=subprocess.STDOUT) + +def error(msg): + sys.stderr.write((unicode(msg) + "\n").encode("UTF-8")) + sys.exit(1) + +def export(svg, options): + for qualifier, dpi in options.densities: + export_density(svg, options, qualifier, dpi) + +def export_density(svg, options, qualifier, dpi): + dir = options.resdir + + if not os.path.exists(dir): + os.makedirs(dir) + + if qualifier == '@1x': + qualifier = '' + + def export_resource(param, name, qualifier): + png = "%s/%s%s.png" % (dir, name, qualifier) + + subprocess.check_call([ "inkscape", + "--without-gui", + param, + "--export-dpi=%s" % dpi, + "--export-png=%s" % png, + svg ], stdout=DEVNULL, stderr=subprocess.STDOUT) + + if options.strip: + subprocess.check_call([ + "convert", "-antialias", "-strip", png, png + ], stdout=DEVNULL, stderr=subprocess.STDOUT) + if options.optimize: + subprocess.check_call([ + "optipng", "-quiet", "-o7", png + ], stdout=DEVNULL, stderr=subprocess.STDOUT) + + if options.source == '"selected_ids"': + for id in options.ids: + export_resource("--export-id=%s" % id, id, qualifier) + else: + export_resource("--export-area-page", options.resname, qualifier) + +def check_boolstr(option, opt, value): + value = value.capitalize() + if value == "True": + return True + if value == "False": + return False + raise optparse.OptionValueError("option %s: invalid boolean value: %s" % (opt, value)) + +class Option(optparse.Option): + TYPES = optparse.Option.TYPES + ("boolstr",) + TYPE_CHECKER = copy(optparse.Option.TYPE_CHECKER) + TYPE_CHECKER["boolstr"] = check_boolstr + +def append_density(option, opt_str, value, parser, *density): + if not value: + return + if getattr(parser.values, option.dest) is None: + setattr(parser.values, option.dest, []) + getattr(parser.values, option.dest).append(density) + +class DensityGroup(optparse.OptionGroup): + def add_density_option(self, name, dpi): + self.add_option("--%s" % name, action="callback", type="boolstr", dest="densities", metavar="BOOL", + callback=append_density, callback_args=(name, dpi), help="Export %s variants" % name.upper()) + +parser = optparse.OptionParser(usage="usage: %prog [options] SVGfile", option_class=Option) +parser.add_option("--source", action="store", type="choice", choices=('"selected_ids"', '"page"'), help="Source of the drawable") +parser.add_option("--id", action="append", dest="ids", metavar="ID", help="ID attribute of objects to export, can be specified multiple times") +parser.add_option("--resdir", action="store", help="Resources directory") +parser.add_option("--resname", action="store", help="Resource name (when --source=page)") + +group = DensityGroup(parser, "Select which densities to export") +group.add_density_option("@1x", 96) +group.add_density_option("@2x", 192) +group.add_density_option("@3x", 288) +parser.add_option_group(group) + +parser.add_option("--strip", action="store", type="boolstr", help="Use ImageMagick to reduce the image size") +parser.add_option("--optimize", action="store", type="boolstr", help="Use OptiPNG to reduce the image size") + +(options, args) = parser.parse_args() +if len(args) != 1: + parser.error("Expected exactly one argument, got %d" % len(args)) +svg = args[0] + +if options.resdir is None: + error("No iOS Resource directory specified") +if not os.path.isdir(options.resdir): + error("Wrong iOS Resource directory specified:\n'%s' is no dir" % options.resdir) +if not os.access(options.resdir, os.W_OK): + error("Wrong iOS Resource directory specified:\nCould not write to '%s'" % options.resdir) +if options.source not in ('"selected_ids"', '"page"'): + error("Select what to export (selected items or whole page)") +if options.source == '"selected_ids"' and options.ids is None: + error("Select at least one item to export") +if options.source == '"page"' and not options.resname: + error("Please enter a resource name") +if not options.densities: + error("Select at least one DPI variant to export") +if not checkForPath("inkscape"): + error("Make sure you have 'inkscape' on your PATH") +if options.strip and not checkForPath("convert"): + error("Make sure you have 'convert' on your PATH if you want to reduce the image size using ImageMagick") +if options.optimize and not checkForPath("optipng"): + error("Make sure you have 'optipng' on your PATH if you want to reduce the image size using OptiPNG") + +export(svg, options)