GitXplorerGitXplorer
k

psd2svg

public
53 stars
17 forks
5 issues

Commits

List of commits on branch master.
Verified
608e30a4a7173bc68f85afd01d39a26c1e81089c

Merge pull request #33 from hansottowirtz/add-isolation

kkyamagu committed 6 months ago
Unverified
aefed363db6581abbdf53b2016a5a684ee05044e

add isolation

hhansottowirtz committed 6 months ago
Verified
324b625f8ffdae2ef6374cf85a0982418b3ca399

Merge pull request #29 from kyamagu/v0.2.3

kkyamagu committed 5 years ago
Unverified
3ca4c7d661be431aab8daa415e2696f4d653a184

Update travis test steps

kkyamagu committed 5 years ago
Unverified
8a26f134829671d485a7d74fc94116b88c3990cc

Update travis test steps

kkyamagu committed 5 years ago
Unverified
50d7bc191da0e8acda134fcad9bfa9a9055fa8fd

Fix for newer psd-tools version

kkyamagu committed 5 years ago

README

The README file for this repository.

PSD2SVG

PSD to SVG converter based on psd-tools_ and svgwrite_.

.. image:: https://img.shields.io/pypi/v/psd2svg.svg :target: https://pypi.python.org/pypi/psd2svg :alt: PyPI Version

.. image:: https://img.shields.io/travis/kyamagu/psd2svg/master.svg :alt: Build Status :target: https://travis-ci.org/kyamagu/psd2svg

.. _psd-tools: https://github.com/psd-tools/psd-tools

.. _svgwrite: https://github.com/mozman/svgwrite

Install

Use pip to install::

pip install psd2svg

Usage

The package comes with a command-line tool::

psd2svg input.psd output.svg

When the output path is a directory, or omitted, the tool infers the output name from the input::

psd2svg input.psd output/  # => output/input.svg
psd2svg input.psd          # => input.svg

When --resource-path flag is specified, all png resources are exported to the path specified by --resource-path::

psd2svg input.psd output.svg --resource-path .
# => output.svg, xxx1.png, ...

psd2svg input.psd output/ --resource-path .
# => output/input.svg, output/xxx1.png, ...

psd2svg input.psd output/ --resource-path=resources/
# => output/input.svg, output/resources/xxx1.png, ...

psd2svg input.psd svg/ --resource-path=../png/
# => svg/input.svg, png/xxx1.png, ...

API

The package contains high-level conversion function psd2svg:

.. code-block:: python

from psd2svg import psd2svg

# File IO.
psd2svg('path/to/input.psd', 'path/to/output/')

# Stream IO.
with open('input.psd', 'rb') as fi:
    with open('output.svg', 'w') as fo:
        psd2svg(fi, fo)

# psd_tools IO.
from psd_tools import PSDImage
psd = PSDImage.load('path/to/input.psd')
svg = psd2svg(psd)
print(svg)

# Additionally, individual layers can be directly rendered.
layer_svg = psd2svg(psd[3])
print(layer_svg)

The package also has rasterizer module to convert SVG to PIL Image:

.. code-block:: python

from psd2svg.rasterizer import create_rasterizer

rasterizer = create_rasterizer()
image = rasterizer.rasterize(svg)
image.save('path/to/output.png')

The rasterizer requires one of Selenium + ChromeDriver, Apache Batik, or Inkscape. Make sure to install them beforehand.

Test

Invoke tox::

tox

Storage backend support

To use AWS S3 storage backend::

pip install psd2svg[s3]

or::

pip install boto3

The tool can specify URL instead of file path (S3 requires boto3)::

psd2svg http://example.com/input.psd
psd2svg s3://bucketname/path/to/input.psd s3://bucketname/path/to/output/

To use HDFS storage backend::

pip install psd2svg[hdfs,kerberos]

Notes

  • SVG 1.1 does not cover all the blending modes in Photoshop (e.g., linear-dodge)
  • Filter effects are approximation. Some effects are not implemented.
  • Most of adjustments layers are not implemented.
  • Smart object filters are not implemented.
  • Browser support: SVG rendering quality greatly differs depending on the browser. Chrome tends to be the best quality.
  • APIs of this tool is NOT thread-safe.
  • To use HDFS storage backend, Python 2.7 environment is needed and should be Kerberos-enabled and only read access is available.