Quick search

Table Of Contents


Core classes for loading images and converting them to a Texture. The raw image data can be keep in memory for further access.

In-memory image loading

New in version 1.9.0: Official support for in-memory loading. Not all the providers support it, but at the moment SDL2, pygame, pil and imageio works.

To load an image with a filename, you usually do:

from kivy.core.image import Image as CoreImage
im = CoreImage("image.png")

Now you can load from memory block. Instead of passing the filename, you’ll need to pass the data as a BytesIO object + an “ext” parameters. Both are mandatory:

import io
from kivy.core.image import Image as CoreImage
data = io.BytesIO(open("image.png", "rb").read())
im = CoreImage(data, ext="png")

By default, the image will not be cached, as our internal cache require a filename. If you want caching, add a filename that represent your file (it will be used only for caching):

import io
from kivy.core.image import Image as CoreImage
data = io.BytesIO(open("image.png", "rb").read())
im = CoreImage(data, ext="png", filename="image.png")
class kivy.core.image.Image(arg, **kwargs)[source]

Bases: kivy.event.EventDispatcher

Load an image and store the size and texture.

Changed in version 1.0.7: mipmap attribute has been added. The texture_mipmap and texture_rectangle have been deleted.

Changed in version 1.0.8: An Image widget can change its texture. A new event ‘on_texture’ has been introduced. New methods for handling sequenced animation have been added.

arg : can be a string (str), Texture or Image object.

A string is interpreted as a path to the image to be loaded. You can also provide a texture object or an already existing image object. In the latter case, a real copy of the given image object will be returned.

keep_data : bool, defaults to False.

Keep the image data when the texture is created.

scale : float, defaults to 1.0

Scale of the image.

mipmap : bool, defaults to False

Create mipmap for the texture.

anim_delay: float, defaults to .25

Delay in seconds between each animation frame. Lower values means faster animation.


Return True if this Image instance has animation available.

New in version 1.0.8.


Delay between each animation frame. A lower value means faster animation.

New in version 1.0.8.


Return the index number of the image currently in the texture.

New in version 1.0.8.


Reset an animation if available.

New in version 1.0.8.

allow_anim: bool

Indicate whether the animation should restart playing or not.


# start/reset animation

# or stop the animation

You can change the animation speed whilst it is playing:

# Set to 20 FPS
image.anim_delay = 1 / 20.

Get/set the filename of image


Image height


Get/set the data image object

static load(filename, **kwargs)[source]

Load an image

filename : str

Filename of the image.

keep_data : bool, defaults to False

Keep the image data when the texture is created.

load_memory(data, ext, filename='__inline__')[source]

(internal) Method to load an image from raw data.


Indicate whether the texture will not be stored in the cache or not.

New in version 1.6.0.

This event is fired when the texture reference or content has
changed. It is normally used for sequenced images.

New in version 1.0.8.

read_pixel(x, y)[source]

For a given local x/y position, return the pixel color at that position.


This function can only be used with images loaded with the keep_data=True keyword. For example:

m = Image.load('image.png', keep_data=True)
color = m.read_pixel(150, 150)
x : int

Local x coordinate of the pixel in question.

y : int

Local y coordinate of the pixel in question.


Remove the Image from cache. This facilitates re-loading of images from disk in case the image content has changed.

New in version 1.3.0.


im = CoreImage('1.jpg')
# -- do something --
im = CoreImage('1.jpg')
# this time image will be re-loaded from disk
save(filename, flipped=False)[source]

Save image texture to file.

The filename should have the ‘.png’ extension because the texture data read from the GPU is in the RGBA format. ‘.jpg’ might work but has not been heavilly tested so some providers might break when using it. Any other extensions are not officially supported.

The flipped parameter flips the saved image vertically, and defaults to True.


# Save an core image object
from kivy.core.image import Image
img = Image('hello.png')

# Save a texture
texture = Texture.create(...)
img = Image(texture)

New in version 1.7.0.

Changed in version 1.8.0: Parameter flipped added to flip the image before saving, default to False.


Image size (width, height)


Texture of the image


Image width

class kivy.core.image.ImageData(width, height, fmt, data, source=None, flip_vertical=True, source_image=None, rowlength=0)[source]

Bases: builtins.object

Container for images and mipmap images. The container will always have at least the mipmap level 0.

add_mipmap(level, width, height, data, rowlength)[source]

Add a image for a specific mipmap level.

New in version 1.0.7.


Image data. (If the image is mipmapped, it will use the level 0)


Indicate if the texture will need to be vertically flipped


Decoded image format, one of a available texture format


Get the mipmap image at a specific level if it exists

New in version 1.0.7.


Image height in pixels. (If the image is mipmapped, it will use the level 0)


Iterate over all mipmap images available.

New in version 1.0.7.


Data for each mipmap.


Image rowlength. (If the image is mipmapped, it will use the level 0)

New in version 1.9.0.


Image (width, height) in pixels. (If the image is mipmapped, it will use the level 0)


Image source, if available


Image width in pixels. (If the image is mipmapped, it will use the level 0)