Table of Contents generated with DocToc
Render text for stickers, labels, etc.
A writing on a letter or document stating its contents; any statement of particulars attached to a package, envelope, etc.; a label or ticket.
>>> import docket
>>>
>>> width = 600 # Explicit width in pixels
>>>
>>> shape, surface = docket.render_text('hello, world!', width=width, font='Serif')
>>>
>>> with open('output.png', 'wb') as image_file:
>>> surface.write_to_png(image_file)
The code above results in the following output:
Note: Any system font name may be specified, e.g., font='Arial'
.
The optional fill
and stroke
arguments (as RGB color tuples) may be used to
change the background fill color and text stroke color, respectively.
For example:
>>> shape, surface = docket.render_text('hello, world!', width=600,
... fill=(1, 0, 0), stroke=(0, 0, 1))
results in the following output:
>>> import docket.util
>>>
>>> docket.util.to_clipboard(surface)
>>> import docket
>>>
>>> shape, surface = docket.render_text(['hello, world!', 'goodbye!'])
>>> import docket
>>> import pandas as pd
>>>
>>>
>>> width = 250 # Explicit width in pixels
>>>
>>> df_data = pd.DataFrame([['Callie', 'Ernst'],
... ['Polly', 'Guerrero'],
... ['Mildred', 'Jones'],
... ['Tomasa', 'Rivera']],
... columns=['first_name', 'last_name'])
>>>
>>> shape, surface = docket.render_frame_text(df_data, width)
The code above results in the following output:
Width/height may be specified as pint
quantities.
For example:
>>> import docket
>>>
>>> # Fit to width of 20 mm (assuming 300 pixels per inch).
>>> width = 20 * docket.UREG.millimeter * 300 * docket.UREG.PPI
>>>
>>> shape, surface = docket.render_text('hello, world!', width=width)
>>> shape
<Quantity([ 236.22047244 72. ], 'pixel')>
>>> shape.magnitude
array([ 236.22047244, 72. ])
The latest docket
release is available as a
Conda package from the sci-bots
channel.
To install docket
in an activated Conda environment, run:
conda install -c sci-bots -c conda-forge docket
This project is licensed under the terms of the BSD license
- Christian Fobel (@sci-bots)