
- Kivy Tutorial
- Kivy - Home
- Kivy Basics
- Kivy - Getting Started
- Kivy - Installation
- Kivy - Architecture
- Kivy - File Syntax
- Kivy - Applications
- Kivy - Hello World
- Kivy - App Life Cycle
- Kivy - Events
- Kivy - Properties
- Kivy - Inputs
- Kivy - Behaviors
- Kivy Buttons
- Kivy - Buttons
- Kivy - Button Events
- Kivy - Button Colors
- Kivy - Button Size
- Kivy - Button Position
- Kivy - Round Buttons
- Kivy - Disabled Buttons
- Kivy - Image Button
- Kivy Widgets
- Kivy - Widgets
- Kivy - Label
- Kivy - Text Input
- Kivy - Canvas
- Kivy - Line
- Kivy - Checkbox
- Kivy - Dropdown List
- Kivy - Windows
- Kivy - ScrollView
- Kivy - Carousel
- Kivy - Slider
- Kivy - Images
- Kivy - Popup
- Kivy - Switch
- Kivy - Spinner
- Kivy - Splitter
- Kivy - Progress Bar
- Kivy - Bubble
- Kivy - Tabbed Panel
- Kivy - Scatter
- Kivy - Accordion
- Kivy - File Chooser
- Kivy - Color Picker
- Kivy - Code Input
- Kivy - Modal View
- Kivy - Toggle Button
- Kivy - Camera
- Kivy - Tree View
- Kivy - reStructuredText
- Kivy - Action Bar
- Kivy - Video Player
- Kivy - Stencil View
- Kivy - VKeyboard
- Kivy - Touch Ripple
- Kivy - Audio
- Kivy - Videos
- Kivy - Spelling
- Kivy - Effects
- Kivy - Input Recorder
- Kivy - OpenGL
- Kivy - Text
- Kivy - Text Markup
- Kivy - Settings
- Kivy Layouts
- Kivy - Layouts
- Kivy - Float Layout
- Kivy - Grid Layouts
- Kivy - Box Layouts
- Kivy - Stack Layout
- Kivy - Anchor Layout
- Kivy - Relative Layout
- Kivy - Page Layout
- Kivy - Recycle Layout
- Kivy - Layouts in Layouts
- Kivy Advanced Concepts
- Kivy - Configuration Object
- Kivy - Atlas
- Kivy - Data Loader
- Kivy - Cache Manager
- Kivy - Console
- Kivy - Animation
- Kivy - Multistroke
- Kivy - Clock
- Kivy - SVGs
- Kivy - UrlRequest
- Kivy - Clipboard
- Kivy - Factory
- Kivy - Gesture
- Kivy - Language
- Kivy - Graphics
- Kivy - Drawing
- Kivy - Packaging
- Kivy - Garden
- Kivy - Storage
- Kivy - Vector
- Kivy - Utils
- Kivy - Inspector
- Kivy - Tools
- Kivy - Logger
- Kivy - Framebuffer
- Kivy Applications and Projects
- Kivy - Drawing App
- Kivy - Calculator App
- Kivy - Stopwatch App
- Kivy - Camera Handling
- Kivy - Image Viewer
- Kivy - Bezier
- Kivy - Canvas Stress
- Kivy - Circle Drawing
- Kivy - Widget Animation
- Kivy - Miscellaneous
- Kivy Useful Resources
- Kivy - Quick Guide
- Kivy - Useful Resources
- Kivy - Discussion
Kivy - Images
Being able to display images is an essential requirement of any GUI application. Kivy framework includes Image widget as an image container. It is capable of loading the image data from png, jpg and GIF files. For SVG files, you may have to another widget named as Svg itself.
Kivy contains two image widgets − Image and AsyncImage. They are defined in the "kivy.uix.image" module.
The Image widget is used to load an image file available in the local machine.
from kivy.uix.image import Image img = Image(source = 'logo.png')
To load any image from any external source, you need to use the AsyncImage widget. AsyncImage class is a subclass of the Image class.
from kivy.uix.image import AsyncImage img = AsyncImage(source = 'http://xyz.com/logo.png')
If you need to display images by retrieving them from URL's, AsyncImage does it in a background thread without blocking your application.
The Image class defines following properties −
source − Filename / source of your image. source is a StringProperty and defaults to None.
fit_mode − If the size of the image is different than the size of the widget, this property determines how the image should be resized to fit inside the widget box.
Available Options
scale-down − For an image bigger than the Image widget dimensions, the image will be scaled down to fit inside the widget box, maintaining its aspect ratio and without stretching. If the size of the image is smaller than the widget, it will be displayed at its original size.
fill − the image is stretched to fill the widget regardless of its aspect ratio or dimensions. This option can lead to distortion of the image, if the image has a different aspect ratio than the widget.
contain − the image is resized to fit inside the widget box, maintaining its aspect ratio. If the image size is larger than the widget size, the behavior will be similar to "scale-down". However, if the size of the image size is smaller than the widget size, unlike "scale-down, the image will be resized to fit inside the widget.
cover − the image will be stretched horizontally or vertically to fill the widget box, maintaining its aspect ratio. If the image has a different aspect ratio than the widget, then the image will be clipped to fit.
texture − Texture object of the image. The texture represents the original, loaded image texture. It is stretched and positioned during rendering according to the fit_mode property.
texture_size − Texture size of the image. This represents the original, loaded image texture size.
color − Image color, in the format (r, g, b, a). This attribute can be used to 'tint' an image. However, if the source image is not gray/white, the color will not really work as expected.
image_ratio − A read-only property that returns Ratio of the image (width / float(height).
reload() − Reload image from disk. This facilitates re-loading of images from disk in case the image content changes.
img = Image(source = '1.jpg') img.reload()
Example
In the following example code, we mainly try to demonstrate the effect of fit_mode property. Given below is a "kv" language script that displays different images in carousel widget. Each image has a different value of fit_mode property.
The "kv" language script is −
Carousel: direction:'top' Image: source:'1.png' fit_mode:"scale-down" Image: source:"TPlogo.png" fit_mode:"contain" Image: source:"TPlogo.png" fit_mode:"fill" Image: source:"TPlogo.png" fit_mode:"cover"
Output
After loading this script in a Kivy App class and running it, different images will be displayed as per the respective fit_mode −
fit_mode = scaled-down
The source is bigger than the Image widget.

fit_mode=contain
Source image smaller than the Image widget.

fit_mode: fill
Image is resized to fit without losing aspect ratio.

fill_mode=cover
Image is stretched to cover the entire widget area.
