Try 9 slices in Python

What is 9 slices?

When scaling a shape, those with corner styles will be distorted and displayed. With 9 slices, you can scale the shape while maintaining its original shape by dividing the shape into 9 areas. 9sliceDisc.png

Advance preparation

Generates an image corresponding to 9 slices. Use Android Asset Studio published by Romannurik. Select Simple nine-patch generator from the top screen and create an image as shown below.

スクリーンショット 2017-04-18 14.51.32.png

Installation of required libraries

Introduce pillow and nine-patch

pip install pillow
pip install ninepatch

code

Create a Ninepatch object with the 9-slice image generated above as an argument. Use the render () method to specify the vertical and horizontal sizes to enlarge the image.

nineSliceTest.py


from ninepatch import Ninepatch
from PIL import Image
bubble = Ninepatch("bubble.9.png ")
scaledBubble = bubble.render(600,200)
scaledBubble.show()

The original image bubbleForBlog.png

Result image result.png

Recommended Posts

Try 9 slices in Python
Try python
Try LINE Notify in Python
Try implementing extension method in python
Try using LevelDB in Python (plyvel)
Try using Leap Motion in Python
About python slices
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
SendKeys in Python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
Python> try: / except:
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Try logging in to qiita with Python
Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try working with binary data in Python
Try sending a SYN packet in Python
Try drawing a simple animation in Python
Quickly try Microsoft's Face API in Python
Try text mining your diary in Python
Try hitting the YouTube API in Python
Try a functional programming pipe in Python
Try something like Python for-else in Ruby
Sorted list in Python
Daily AtCoder # 36 in Python
Clustering text in Python