| 1 |
.. module:: cairocffi.pixbuf |
| 2 |
|
| 3 |
Decoding images with GDK-PixBuf |
| 4 |
=============================== |
| 5 |
|
| 6 |
The |
| 7 |
:meth:`ImageSurface.create_from_png() <cairocffi.ImageSurface.create_from_png>` |
| 8 |
method can decode PNG images and provide a cairo surface, |
| 9 |
but what about other image formats? |
| 10 |
|
| 11 |
The :mod:`cairocffi.pixbuf` module uses GDK-PixBuf_ |
| 12 |
to decode JPEG, GIF, and various other formats (depending on what is installed.) |
| 13 |
If you don’t import this module, |
| 14 |
it is possible to use the rest of cairocffi without having GDK-PixBuf installed. |
| 15 |
GDK-PixBuf is an independent package since version 2.22, |
| 16 |
but before that was part of `GTK+`_. |
| 17 |
|
| 18 |
.. _GDK-PixBuf: https://live.gnome.org/GdkPixbuf |
| 19 |
.. _GTK+: http://www.gtk.org/ |
| 20 |
|
| 21 |
This module also converts pixel data |
| 22 |
since the internal format in GDK-PixBuf (big-endian RGBA) |
| 23 |
is not the same as in cairo (native-endian ARGB). |
| 24 |
For this reason, although it is a "toy" API, |
| 25 |
:meth:`ImageSurface.create_from_png() <cairocffi.ImageSurface.create_from_png>` |
| 26 |
can be faster than :func:`decode_to_image_surface` |
| 27 |
if the format is known to be PNG. |
| 28 |
The pixel conversion is done by GTK+ if available, |
| 29 |
but a (slower) fallback method is used otherwise. |
| 30 |
|
| 31 |
.. autoexception:: ImageLoadingError |
| 32 |
.. autofunction:: decode_to_image_surface |