Skip to content
This repository has been archived by the owner on Jan 30, 2023. It is now read-only.

Update README.md with install path on Windows. #11

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
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.

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`,`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`

A restart of Inkscape is required.

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
Expand Down
12 changes: 6 additions & 6 deletions android_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
35 changes: 35 additions & 0 deletions ios_export.inx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<inkscape-extension xmlns="http://www.inkscape.org/namespace/inkscape/extension">
<_name>iOS Export</_name>
<id>de.cbecker.ios_export</id>

<dependency type="executable" location="extensions">ios_export.py</dependency>

<param name="source" type="notebook">
<page name="selected_ids" _gui-text="Selection">
<_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>
</page>
<page name="page" _gui-text="Page">
<_param name="title" type="description">Exports the entire page in different densities.</_param>
<param name="resname" type="string" _gui-text="Resource name" />
</page>
</param>

<param name="resdir" type="string" _gui-text="iOS Resource directory"></param>
<param name="@1x" type="boolean" _gui-text="Export @1x">true</param>
<param name="@2x" type="boolean" _gui-text="Export @2x">true</param>
<param name="@3x" type="boolean" _gui-text="Export @3x">true</param>
<param name="strip" type="boolean" _gui-text="Use ImageMagick to reduce the image size">false</param>
<param name="optimize" type="boolean" _gui-text="Use OptiPNG to reduce the image size">true</param>

<effect needs-live-preview="false">
<object-type>all</object-type>
<effects-menu>
<submenu _name="Export"/>
</effects-menu>
</effect>

<script>
<command reldir="extensions" interpreter="python">ios_export.py</command>
</script>
</inkscape-extension>
144 changes: 144 additions & 0 deletions ios_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#!/usr/bin/env python

# ***** BEGIN APACHE LICENSE BLOCK *****
#
# Copyright 2013 Christian Becker <[email protected]>
#
# 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)