skip to navigation
skip to content

Not Logged In

ninepatch 0.1.19

Slice and scale 9-patch images

Slice Android style 9-patch images, resize and interactively preview them.

See https://developer.android.com/tools/help/draw9patch.html for a 9-patch description.

Installation

If you want to use the interactive viewer read the additional installation notes under “Interactive viewer”.

$ pip install ninepatch

Python usage

from ninepatch import Ninepatch
ninepatch = Ninepatch('ninepatch_bubble.9.png')
print(ninepatch.content_area)  # content_area(left=23, top=20, right=27, bottom=59)
scaled_image = ninepatch.render(500, 400) # creates a new PIL image

Command line usage

Your image must be a PNG image with a transparent background. The scale and fill guide color must be 100% opaque black.

Scale and open image in a viewer (PIL image.show()):

$ ninepatch render ninepatch_bubble.9.png 300 300

Save the scaled image to a new file:

$ ninepatch render ninepatch_bubble.9.png 300 300 scaled.png

Slice the 9patch into tiles:

$ ninepatch slice ninepatch_bubble.9.png ./outputdir

Interactive viewer

Interactively resize and preview an image in a Tkinter viewer:

$ ninepatch_viewer ninepatch_bubble.9.png

or just:

$ ninepatch_viewer

without arguments to see the demo image

If you want to use the viewer then python-pil.imagetk has to be installed.

On Ubuntu do:

$ sudo apt-get install python-pil.imagetk

If you want to install into a virtualenv, pip needs the following packages to compile PIL with Tkinter support:

$  sudo apt-get install python-tk tk8.6-dev

(You can trigger a recompile of PIL with: “pip install -I ninepatch”)

Changelog

0.1.19
  • fixed error in caching
0.1.18
  • optional caching for slice() and render()
0.1.17
  • new method export_slices()
  • changed command line parameters (render/slice)
0.1.10
  • missing guides are now handled properly
0.1.9
  • parse the fill area
  • switched to setuptools
0.1.4
  • added Tkinter viewer

Notes

I wrote this tool for the ninepatch_actor.py in my Clutter example project: https://github.com/vindolin/Clutter-Python-examples

Issues

TODO

 
File Type Py Version Uploaded on Size
ninepatch-0.1.19.tar.gz (md5) Source 2014-09-07 12KB
  • Downloads (All Versions):
  • 40 downloads in the last day
  • 204 downloads in the last week
  • 577 downloads in the last month
  • Author: Thomas Schüßler
  • Home Page: https://github.com/vindolin/ninepatch
  • Bug Tracker: https://github.com/vindolin/ninepatch/issues
  • License:
    The MIT License (MIT)
    
    Copyright (c) 2014 Thomas Schüßler
    
    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:
    
    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.
    
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    SOFTWARE.
  • Package Index Owner: vindolin
  • DOAP record: ninepatch-0.1.19.xml