Git Product home page Git Product logo

inkscape-9-patch-export's Introduction

Inkscape 9-patch Export Extension

This is an Inkscape extension that exports each top-level layer in an SVG as PNG images.

Based on Johann Woelper's fork of the original extension from Jesús Espino and Xavier Julian.

How it works

Copy export_9_patch.inx and export_9_patch.py into Inkscape's extension directory, which can be found via Edit > Preferences > System > User preferences.

This extension will export each top-level layer into a PNG image whose filename is the layer's name. The exported area is the drawing (not page), i.e. the bounding box of all objects in the layer. The exported image will display all of the visible objects in the layer without margins or cropping.

Layers with a "[9] " prefix will be exported with a .9.png extension. For example, [9] button-background will be exported as button-background.9.png.

Layers with a "[NoExport] " prefix will not be exported.

There are also options to export the layer in certain high DPI variants. The resulting images will contain the DPI as a suffix; e.g. [email protected].

Using it

To use the extension:

  1. Open the extension's dialog via Extensions > Export > Export 9-patch PNGs...
  2. Provide the path to the output directory where the images should be saved to (Inkscape's extension system does not allow file dialogs, unfortunately).
  3. Choose the DPI variants that should be exported.
  4. Click Apply.

9-patch Tips

If you have an asset that doesn't have 9-patch lines on every side, it can be useful to either:

  • Add an unfilled rectangle behind the entire asset, or;
  • Add a 1 x 1 unfilled rectangle where necessary

This ensures that the bounds will leave the space for the missing 9-patch lines. For example:

9-patch example

After being made transparent (unfilled), the 1 pixel rectangle on the bottom right corner ensures that there are one pixel gaps on the sides of the image. If the above 50 x 32 button is exported @4x, the resulting image will look like this:

9-patch export example

At 4 times the size, the button itself will be 200 x 128, but since the 9-patch lines are included in the bounds, it becomes 208 x 136 (4 pixels top, 4 pixels bottom, etc.). The 9-patch system requires one pixel thick lines, and so these will need to be trimmed. The simplest way to trim images in bulk is to use imagemagick:

  • For @2x images: convert *@2x.9.png -shave 1x1 *@2x.9.png
  • For @3x images: convert *@3x.9.png -shave 2x2 *@3x.9.png
  • For @4x images: convert *@4x.9.png -shave 3x3 *@4x.9.png

The image above will look like this once fixed:

9-patch export fixed example

Alternatively, if you're using the assets with Qt Quick Controls 2's Imagine Style, you can use the testbench tool to preview and fix the assets for you.

inkscape-9-patch-export's People

Contributors

mitchcurtis avatar jespino avatar xaviju avatar hstefan avatar jsfdez avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.