Skip to main content

License: GPL v3 PyPI3 PyPI1

PIL Text Scaler

Module for automatically fitting a string of text inside of a specified area.

Usage

Loading a Font

To use a font with this module, it first needs to be loaded. The function loadTTF is used to load a True Type Font file. It takes 4 arguments: the name to be used for the font, the path of the font, an optional encoding, an option to load the fast version of the font, an optional minimum size, and an optional maximum size.

import PTS

PTS.loadTTF('arial', 'arial.ttf')

Scaling Text

To figure out if a string of text will fit in an area with the current settings, all you need to do is use the main function of the module: fitText. The function takes 5 arguments: the text to be fit, the width of the area in pixels, the height of the area in pixels, an optional font name (defaults to “consolas”), an optional minimum size to use (use None to try all available sizes), and an option to use fast fonts, when available. The function returns a tuple of the wrapped text, the font that worked, and the size of said font, in that order.

import PTS

text = "This is a string of text to be fit."

PTS.loadTTF('arial', 'arial.ttf') # Load the font
result = PTS.fitText(text, 100, 500, 'arial', 23, fast = True)

Getting the Minimum and Maximum Text Sizes

If you would like to get information on the sizes that a font is using, you can use the getSize function. It takes a font name and returns a dictionary with size information about that font.

import PTS

information = PTS.getSize('arial')

Changing the Minimum and Maximum Text Sizes

If you would like to change the minimum and maximum text sizes (as well as the difference between each size the module tries) you can use the setSize function. This function will change an existing font or will change the defaults for new fonts if no font has been specified. It takes 4 parameters: minimum size (inclusive), the maximum size (exclusive), an optional step parameter which is used to tell it how for to space each valid size from each other, and the name of a font to change. The default for these values are 15, 35, 2, and None, respectively.

import PTS

minimum = 30
maximum = 60
step = 2

PTS.setSizes(30, 60, 2) # Changes the default for new fonts.
PTS.loadTTF('arial', 'arial.ttf') # Will load using the new sizes.

Fast Fonts

Fast fonts are a way to process the text data much faster. The downsides are that they are memory intensive, taking longer to load, and are slightly less accurate. Fonts that have characters that overlap will be less accurate, sometimes by a large number of pixels.

Metadata

Release files for PTS 1.4.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PTS 1.4.8
File Size Uploaded Provenance Actions
PTS-1.4.8.tar.gz 18.3 kB Without provenance Details for PTS-1.4.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PTS 1.4.8
File Interpreter ABI Platform Actions
PTS-1.4.8-py3-none-any.whl Python 3 none any Details for PTS-1.4.8-py3-none-any.whl

Total release size: 37.4 kB

Release files / PTS-1.4.8.tar.gz

Download URL PTS-1.4.8.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
e5147f22736dc6bc2f30866ce26f47342faecafb641cef4ad5fa41ac797dea61
BLAKE2b-256 checksum
How to use checksums
b4ae861a2afc4dbb731aa6d6be645d7b13e3f3d750b3e6a6c48c1989374a5e97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Release files / PTS-1.4.8-py3-none-any.whl

Download URL PTS-1.4.8-py3-none-any.whl
Size 19.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d7b6811a6d145273c29d5df8566df356ca291077053d2d6fbb07472bbd290291
BLAKE2b-256 checksum
How to use checksums
d2ec7fec324626ec59e1345ebd925528bf78260043b16592f4aae1a0f44b6ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

Security for PTS 1.4.8

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page