RAD Studio 10.4.1 is now available! Learn more. Looking for discounts? Visit our Special Offers page!
C++CodeDelphi

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

Are you looking for a simple way to process images programmatically? You can do it with Python for Delphi using Pillow library. Python for Delphi (P4D) is a free tool that allows you to execute Python scripts, create new Python modules and types in Delphi. This post will guide you on how to run Pillow library code using Python for Delphi.

You can easily build Python GUI apps using your favorite Python libraries for Windows using Delphi and C++Builder and Python4Delphi. In order to run the Python script in Python for Delphi, open and run project Demo1. Then insert the script into lower Memo, click Execute button, and get the result in upper Memo. You can find the Demo1 source on GitHub.

pillow_4

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

Open, show, and get image properties

First, open the image using function open(). You can get image properties such as format, size, type.

Create thumbnails

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

Geometrical transformations

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

pillow_2

Change images colors

Now let’s look at how to change image color. Function split() allows you to decompose the image into separate colors and work with each color separately. In the following example first, we split the image into separate parts by color. Then select the area where the green value is less than 150. At the next step, we increase the blue value by 0.5. In the end, we merge everything into a new image.

pillow_3

Now you can make various modifications with your images using Pillow library and Python for Delphi. Go here to download Pillow library. Check out Python4Delphi which easily allows you to build Python GUIs for Windows using Delphi.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Learn More About Upgrading

Related posts
C++CodeDelphi

Manage Your Collection Of Pages Easily With TCardPanel Component For Your Delphi VCL Application

CodeDelphiRAD Studio

Learn How To Use FireDAC In The Dynamic-Link Libraries With DLL Sharing Sample In Delphi

C++CodeDelphi

Learn To Build A Python GUI For Working with HTTP Requests With Requests Library In A Delphi Windows App

DelphiShowcase

Lovingly Crafted Software To Plan And Simulate Virtual Model Railroads Is Built In Delphi

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES