Skip to main content

Freetype python bindings

Project description

FreeType (high-level Python API)

Freetype Python provides bindings for the FreeType library. Only the high-level API is bound.

Documentation available at: http://freetype-py.readthedocs.org/en/latest/

Installation

From PyPI, recommended: pip install freetype-py. This will install the library with a bundled FreeType binary, so you’re ready to go on Windows, macOS and Linux (all with 32 and 64 bit x86 architecture support).

Do note: if you specify the –no-binary paramater to pip, or use a different architecture for which we don’t pre-compile binaries, the package will default to using an external FreeType library. Specify the environment variable FREETYPEPY_BUNDLE_FT=1 before calling pip to compile a binary yourself.

Installation with compiling FreeType from source

If you don’t want to or can’t use the pre-built binaries, build FreeType yourself: export FREETYPEPY_BUNDLE_FT=yesplease && pip install .. This will download and compile FreeType with Harfbuzz support as specified in setup-build-freetype.py. Set the environment variable PYTHON_ARCH to 32 or 64 to explicitly set an architecture, default is whatever your host machine uses. On macOS, we will always build a universal 32 and 64 bit Intel binary.

  • Windows: You need CMake and a C and C++ compiler, e.g. the Visual Code Community 2017 distribution with the desktop C++ workload.

  • macOS: You need CMake and the XCode tools (full IDE not necessary)

  • Linux: You need CMake, gcc and g++. For building a 32 bit library on a 64 bit machine, you need gcc-multilib and g++-multilib (Debian) or glibc-devel.i686 and libstdc++-devel.i686 (Fedora).

Installation with an external FreeType library (the default)

Install just the pure Python library and let it find a system-wide installed FreeType at runtime.

Mac users

Freetype should be already installed on your system. If not, either install it using homebrew or compile it and place the library binary file in ‘/usr/local/lib’.

Linux users

Freetype should be already installed on your system. If not, either install relevant package from your package manager or compile from sources and place the library binary file in ‘/usr/local/lib’.

Window users

There are no official Freetype binary releases available, but they offer some links to precompiled Windows DLLs. Please see the FreeType Downloads page for links. You can also compile the FreeType library from source yourself.

If you are using freetype-py on Windows with a 32-Bit version of Python, you need the 32-Bit version of the Freetype binary. The same applies for a 64-Bit version of Python.

Because of the way Windows searches for dll files, make sure the resulting file is named ‘freetype.dll’ (and not something like Freetype245.dll). Windows expects the library in one of the directories listed in the $PATH environment variable. As it is not recommended to place the dll in a Windows system folder, you can choose one of the following ways to solve this:

  • Place library in a folder of your choice and edit the $PATH user environment variable

  • Place library in a folder of your choice and edit the $PATH system environment variable

  • For development purpose, place the library in the working directory of the application

  • Place the library in one of the existing directories listed in $PATH

To get a complete list of all the directories in the $PATH environment variable (user and system), open a command promt and type

echo %PATH%

Usage example

import freetype
face = freetype.Face("Vera.ttf")
face.set_char_size( 48*64 )
face.load_char('S')
bitmap = face.glyph.bitmap
print bitmap.buffer

Screenshots

Screenshot below comes from the wordle.py example. No clever tricks here, just brute force.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/wordle.png

Screenshots below comes from the glyph-vector.py and glyph-vectopr-2.py examples showing how to access a glyph outline information and use it to draw the glyph. Rendering (with Bézier curves) is done using matplotlib.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/S.png https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/G.png

Screenshot below comes from the glyph-color.py showing how to draw and combine a glyph outline with the regular glyph.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/outline.png

The screenshot below comes from the hello-world.py example showing how to draw text in a bitmap (that has been zoomed in to show antialiasing).

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/hello-world.png

The screenshot below comes from the agg-trick.py example showing an implementation of ideas from the Texts Rasterization Exposures by Maxim Shemarev.

https://raw.githubusercontent.com/rougier/freetype-py/master/doc/_static/agg-trick.png

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

freetype-py-2.0.0.post6.tar.gz (601.4 kB view details)

Uploaded Source

Built Distributions

freetype_py-2.0.0.post6-py2.py3-none-win_amd64.whl (570.4 kB view details)

Uploaded Python 2 Python 3 Windows x86-64

freetype_py-2.0.0.post6-py2.py3-none-win32.whl (496.2 kB view details)

Uploaded Python 2 Python 3 Windows x86

freetype_py-2.0.0.post6-py2.py3-none-manylinux1_x86_64.whl (703.8 kB view details)

Uploaded Python 2 Python 3

freetype_py-2.0.0.post6-py2.py3-none-manylinux1_i686.whl (697.0 kB view details)

Uploaded Python 2 Python 3

freetype_py-2.0.0.post6-py2.py3-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.2 MB view details)

Uploaded Python 2 Python 3 macOS 10.10+ intel macOS 10.10+ x86-64 macOS 10.6+ intel macOS 10.9+ intel macOS 10.9+ x86-64

freetype_py-2.0.0.post6-py2.py3-none-any.whl (69.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file freetype-py-2.0.0.post6.tar.gz.

File metadata

File hashes

Hashes for freetype-py-2.0.0.post6.tar.gz
Algorithm Hash digest
SHA256 23c9dcd9c1797507b0e083c18848d476c72128137ca485665d149ce231001069
MD5 b9a44744801bcfe143e4e44d06070b8b
BLAKE2b-256 f7c7aaefd002da8351639ebbecfffde2b78ef565d96dcabe18d437ae28fe40c2

See more details on using hashes here.

File details

Details for the file freetype_py-2.0.0.post6-py2.py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for freetype_py-2.0.0.post6-py2.py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 e93390054bc480e0684740f2f46236ea81d591d9c94c1a884e86cb0378c65b98
MD5 1218c94dfd64dab75a96ef5ff58689d0
BLAKE2b-256 1f9a4efb17fe0eade48b4e7b3781934df7ac1e0480c0d4077117ff6ed05833b1

See more details on using hashes here.

File details

Details for the file freetype_py-2.0.0.post6-py2.py3-none-win32.whl.

File metadata

File hashes

Hashes for freetype_py-2.0.0.post6-py2.py3-none-win32.whl
Algorithm Hash digest
SHA256 d3dfe653f0bfa009befe2b63e7043a9dbac2c7a0b81292b48c787301adc868ec
MD5 4a2615742a4145677a1d25182947938e
BLAKE2b-256 ca639385a01bc7942a0250def599c4a1db0cd37b8e65f3f0c7ce6c1478f7df7f

See more details on using hashes here.

File details

Details for the file freetype_py-2.0.0.post6-py2.py3-none-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for freetype_py-2.0.0.post6-py2.py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 6bca37436cf236d1dabcb3378ad4fd0275b1857aac90e7f2ed6ee2dca6c2b0b0
MD5 48a2a57a973141886c0e7ac34816f786
BLAKE2b-256 8015e284bb2d3e6a3d42d5455d189084bbff0fa024c2c2f4f0dec66e7667c476

See more details on using hashes here.

File details

Details for the file freetype_py-2.0.0.post6-py2.py3-none-manylinux1_i686.whl.

File metadata

File hashes

Hashes for freetype_py-2.0.0.post6-py2.py3-none-manylinux1_i686.whl
Algorithm Hash digest
SHA256 edfeba3fe9d9e68bdd3368a1fa9c772a474ba3420cda8169dca570868d20526c
MD5 35ca7e9ccb870485d45d50e0f7e5f2d7
BLAKE2b-256 1297c7f5115a2bc08c34cbe8ef23f6dcb94550ea2f97648843bc6c6e69057c2b

See more details on using hashes here.

File details

Details for the file freetype_py-2.0.0.post6-py2.py3-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl.

File metadata

File hashes

Hashes for freetype_py-2.0.0.post6-py2.py3-none-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Algorithm Hash digest
SHA256 ee441e568dc1fdbbe44bd4dc204de755fcbca47ff45426d66b05f93e78496131
MD5 c9a79617ebf8bc909fadccacd5231020
BLAKE2b-256 8585fc07451dfb2413303160cf7a7505177fb275086dc56e29e9183d299be61f

See more details on using hashes here.

File details

Details for the file freetype_py-2.0.0.post6-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for freetype_py-2.0.0.post6-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 fb0f169b68fd842fabbec52378cf55fba26a1d74ad3dfb4fb9de133fe9903b4a
MD5 76e5d450b7e25e5fb18cc26cfd32440a
BLAKE2b-256 de8b03fd6dd27ec07b2b1a778e0d851a518e7707ae8d9d40d832752e38ed7ac0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page