Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.
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
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ icons:

- path: Resources/images/android
prepend: 'ic_'
dpi: 82
screen-dpi: 480
width-dp: 30
height-dp: 30

images:
- icons/foo.ai
Expand Down Expand Up @@ -98,9 +100,15 @@ You can use wildcards (as well as other special characters supported by
Python's [glob module](https://docs.python.org/3.1/library/glob.html)) to specify
groups of images under a path.

Since Illustrator accepts a 'scaling' property for rendering and not a DPI,
Since Illustrator accepts a `scaling` property for rendering and not a DPI,
it is assumed your files were created with a DPI of 72. If they weren't,
use the 'srcdpi' to specify the source dpi.
use the `srcdpi` to specify the source dpi.

Inkscape accepts pixel and density-independent dimension properties.
To specify output dimensions in pixels, use `width-px` and `height-px`.
To specify output dimensions in density-independent pixels, use `width-dp`,
`height-dp`, and `screen-dpi`, where `screen-dpi` is the target device screen DPI.
These properties override `dpi` - they're mutually exclusive.

If you create `images/Icon.svg` at 57x57 *points* in inkscape, the above group
called `appicons`
Expand Down
51 changes: 45 additions & 6 deletions plugin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python

import os, subprocess, inspect, yaml, shutil, sys, glob
from math import ceil

class ModCheck (object):
"""handles checking of modification times to see if we need to
Expand Down Expand Up @@ -36,6 +37,10 @@ def launch (command):
print unicode(err, errors='ignore')
raise Exception('Command failed, check output')

def dp_to_px (dp, screen_dpi):
"""Translate density-independent pixels to pixels for a given screen DPI."""
return int(ceil(dp * (screen_dpi/float(160))))

def illustrator (infile, outfile, outputConfig, pluginConfig):
"""Render an image with illustrator"""
print 'Rendering', infile, 'to', outfile, 'at dpi', outputConfig['dpi'], 'with Illustrator.'
Expand All @@ -58,15 +63,49 @@ def illustrator (infile, outfile, outputConfig, pluginConfig):

def inkscape (infile, outfile, outputConfig, pluginConfig):
"""Render an image with inkscape"""
print 'Rendering', infile, 'to', outfile, 'at dpi', outputConfig['dpi'], 'with Inkscape.'
command = [
"inkscape",
"-d",
str(outputConfig['dpi']),
command = ["inkscape"]

# Use pixel dimension properties (width-px, height-px)
if {'width-px', 'height-px'} <= set(outputConfig):

print 'Rendering', infile, 'to', outfile, 'at', outputConfig['width-px'], 'x', outputConfig['height-px'], 'px with Inkscape.'
command.extend([
"-w",
str(outputConfig['width-px']),
"-h",
str(outputConfig['height-px'])
])

# Use density-independent pixel dimension properties (width-dp, height-dp, screen-dpi)
elif {'width-dp', 'height-dp', 'screen-dpi'} <= set(outputConfig):

print 'Rendering', infile, 'to', outfile, 'at', outputConfig['width-dp'], 'x', outputConfig['height-dp'], 'dp for', outputConfig['screen-dpi'], 'DPI screen with Inkscape.'
width_px = dp_to_px(outputConfig['width-dp'], outputConfig['screen-dpi'])
height_px = dp_to_px(outputConfig['height-dp'], outputConfig['screen-dpi'])
command.extend([
"-w",
str(width_px),
"-h",
str(height_px)
])

# Use DPI property
elif 'dpi' in outputConfig:
print 'Rendering', infile, 'to', outfile, 'at dpi', outputConfig['dpi'], 'with Inkscape.'
command.extend([
"-d",
str(outputConfig['dpi'])
])

else:
raise Exception("Invalid Inkscape export configuration for " + outfile)

command.extend([
"-e",
outfile,
infile
]
])

launch(command)

def checkProps (names, pluginConfig, outputConfig):
Expand Down