### Install Ninepatch Library Source: https://github.com/vindolin/ninepatch/blob/master/README.md Install the ninepatch library using pip. This is the basic installation for command-line and Python usage. ```bash pip install ninepatch ``` -------------------------------- ### Interactive Viewer: Launch Ninepatch Viewer Source: https://github.com/vindolin/ninepatch/blob/master/README.md Launch the interactive ninepatch viewer to resize and preview images. Requires `python-pil.imagetk` to be installed. ```bash $ ninepatch-viewer ninepatch_bubble.9.png ``` ```bash $ ninepatch-viewer ``` -------------------------------- ### Command Line: Get Ninepatch Slicing Info as JSON Source: https://github.com/vindolin/ninepatch/blob/master/README.md Extract slicing and content area information from a ninepatch image and output it as a JSON object. The input must be a PNG with an opaque black guide. ```bash $ ninepatch info ninepatch_bubble.9.png ``` -------------------------------- ### Install Tkinter Support for PIL on Ubuntu Source: https://github.com/vindolin/ninepatch/blob/master/README.md Install necessary packages on Ubuntu to enable Tkinter support for PIL, which is required for the interactive viewer. ```bash $ sudo apt-get install python-pil.imagetk ``` -------------------------------- ### Command Line: Fit Ninepatch to Dimensions and Save Source: https://github.com/vindolin/ninepatch/blob/master/README.md Render a ninepatch image so its content area fits given dimensions and save the result to a file. The input must be a PNG with an opaque black guide. ```bash $ ninepatch fit ninepatch_bubble.9.png 150 150 fit.png ``` -------------------------------- ### Command Line: Wrap Image with Ninepatch and Save Source: https://github.com/vindolin/ninepatch/blob/master/README.md Render a ninepatch image to include another image and save the result. The input ninepatch PNG must have an opaque black fill/scale guide. ```bash $ ninepatch wrap ninepatch_bubble.9.png image_to_wrap.png wrapped.png ``` -------------------------------- ### Install Tkinter Development Packages in Virtualenv Source: https://github.com/vindolin/ninepatch/blob/master/README.md Install Tkinter development packages required for compiling PIL with Tkinter support within a virtual environment. ```bash $ sudo apt-get install python-tk tk8.6-dev ``` -------------------------------- ### Command Line: Render and Save Ninepatch Source: https://github.com/vindolin/ninepatch/blob/master/README.md Render a ninepatch image to a specified size and save it to a new PNG file. Ensure the input PNG has an opaque black fill/scale guide. ```bash $ ninepatch render ninepatch_bubble.9.png 300 300 scaled.png ``` -------------------------------- ### Command Line: Slice Ninepatch into Tiles Source: https://github.com/vindolin/ninepatch/blob/master/README.md Slice a ninepatch image into individual tiles and save them to a specified output directory. The input must be a PNG with an opaque black guide. ```bash $ ninepatch slice ninepatch_bubble.9.png ./outputdir ``` -------------------------------- ### Command Line: Render and Show Ninepatch Source: https://github.com/vindolin/ninepatch/blob/master/README.md Render a ninepatch image to a specified size and display it using PIL's default image viewer. The image must be a PNG with an opaque black fill/scale guide. ```bash $ ninepatch render ninepatch_bubble.9.png 300 300 ``` -------------------------------- ### Reinstall Ninepatch with PIL Tkinter Support Source: https://github.com/vindolin/ninepatch/blob/master/README.md Force a reinstallation of the ninepatch library to ensure PIL is compiled with Tkinter support, especially after installing development packages. ```bash "pip install -I ninepatch" ``` -------------------------------- ### Python Usage: Render Ninepatch to Fit Dimensions Source: https://github.com/vindolin/ninepatch/blob/master/README.md Render a ninepatch image so that its content area fits within the specified width and height. The aspect ratio is maintained. ```python # render the image so it's content area fits (width, height) image_fit = ninepatch.render_fit(300, 200) ``` -------------------------------- ### Python Usage: Render Ninepatch to Specific Size Source: https://github.com/vindolin/ninepatch/blob/master/README.md Render a ninepatch image to a new PIL image with specified width and height. This scales the image to exact dimensions. ```python # render the image to a specific size scaled_image = ninepatch.render(500, 400) # creates a new PIL image ``` -------------------------------- ### Ninepatch Slicing Information (JSON) Source: https://github.com/vindolin/ninepatch/blob/master/README.md JSON output detailing the scale and fill marks, as well as the overall size of the ninepatch image. ```json { "marks": { "fill": { "x": [ 23, 231 ], "y": [ 20, 82 ] }, "scale": { "x": [ [ 49, 49 ], [ 89, 196 ] ], "y": [ [ 42, 63 ] ] } }, "size": [ 258, 141 ] } ``` -------------------------------- ### Python Usage: Render Ninepatch to Wrap Another Image Source: https://github.com/vindolin/ninepatch/blob/master/README.md Render a ninepatch image to contain another PIL image. The ninepatch will scale to accommodate the wrapped image. ```python # render the image so it wraps another PIL image image_to_wrap = Image.open('image_to_wrap.png') wrapped_image = ninepatch.render_wrap(image_to_wrap) ``` -------------------------------- ### Python Usage: Load and Inspect Ninepatch Source: https://github.com/vindolin/ninepatch/blob/master/README.md Load a ninepatch image in Python and access its content area properties. Requires the Pillow library for image manipulation. ```python from ninepatch import Ninepatch ninepatch = Ninepatch('ninepatch_bubble.9.png') print(ninepatch.content_area) # content_area(left=23, top=20, right=27, bottom=59) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.