DelphiPythonPython GUIWindows

Learn To Build A Python GUI For Easily Processing Images With Pillow Library In A Delphi Windows App


Are you looking for a simple way to process images programmatically, and build a nice GUI for them? You can do it easily by combining Python4Delphi and Pillow library, inside Delphi and C++Builder. Python4Delphi (P4D) is a free tool that allows you to execute Python scripts, create new Python modules and types in Delphi.

Pillow or PIL is the Python Imaging Library that adds image processing capabilities to your Python interpreter. This library provides extensive file format support, an efficient internal representation, and fairly powerful image processing capabilities. The core image library is designed for fast access to data stored in a few basic pixel formats. It should provide a solid foundation for a general image processing tool.

This post will guide you on how to manipulate an image via Python’s Pillow and then display it in the Delphi Windows GUI app.

First, open and run our Python GUI using project Demo1 from Python4Delphi with RAD Studio. Then insert the script into the lower Memo, click the Execute button, and get the result in the upper Memo. You can find the Demo1 source on GitHub. The behind the scene details of how Delphi manages to run your Python code in this amazing Python GUI can be found at this link.


With the Pillow library, you can perform geometric and color transformations. It also allows you to cut, copy part of the image and merge several images into one. Let’s take a look at some examples.


1. Open, Show, and Get Image Properties

First, let’s open the image using the function open(). We can get image properties such as format, size, type:

Run the script above in Demo01 GUI, we will get the following results:



2. Create Thumbnails or Resize Image

thumbnail() function allows us to create an image thumbnail. The input parameters of this function are the size of the image that we want to get in pixels. Use the save() function to save the image in a specified directory:

Run the script above, we will get the following result:


The cat image was resized to 250×167 (the previous image size is 1080×720).


3. Geometric Transformations

Function transpose() allows us to perform different geometrical transformations with the image. For example, we can rotate the image by a given angle or flip it horizontally or vertically:

Run the script above, we will get the following result:


Cool, wasn’t it?


4. Change Images Colors

Now let’s look at how to change image color automatically. The following code will change all the white (also shades of whites) pixels to yellow, and in the end, we merge everything into a new image:

Let’s see this interesting result:


Congratulations, now you have learned how to manipulate an image via Python’s Pillow and then display it in the Delphi Windows GUI App! Now you can make various modifications to your images using Pillow library and Python4Delphi. The only limitation is your imagination.

Check out the Pillow image processing for Python and use it in your projects: and

Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi:

Related posts
AndroidCodeDelphiDelphiFMXIDELearn PythonProjectsPythonPython GUI

How To Create A Calculator App Using Python GUI?

DelphiFMXDelphiVCLNewsPythonPython GUI

Introducing Python 3.11 And Documentation Support To The DelphiFMX And DelphiVCL GUI Python Packages

AndroidCodeDelphiDelphiFMXLearn PythonPythonPython GUI

How To Create A Tic-Tac-Toe Game Using Delphi Python EcoSystem

CodeDelphiDelphiFMXPythonPython GUI

How To Write A Simple Todo Gui Application Using Delphifmx

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *