🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › Image.html
Image module - Pillow (PIL Fork) 12.2.0 documentation
The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pil-image-new-method
Python PIL | Image.new() method - GeeksforGeeks
July 12, 2025 - Syntax: PIL.Image.new(mode, size) PIL.Image.new(mode, size, color) Parameters: mode: The mode to use for the new image. (It could be RGB, RGBA) size: A 2-tuple containing (width, height) in pixels. color: What color to use for the image. Default is black. If given, this should be a single integer or floating point value for single-band modes, and a tuple for multi-band modes.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
PIL Image.new() help - Raspberry Pi Forums
pi@rpitest64:~ $ python3 Python 3.9.2 (default, Feb 28 2021, 17:03:44) [GCC 10.2.1 20210110] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from PIL import Image >>> im = Image.new("RGB", (200,200)) >>> im <PIL.Image.Image image mode=RGB size=200x200 at 0x7F8C5E0FA0> >>>
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › handbook › concepts.html
Concepts - Pillow (PIL Fork) 12.2.0 documentation
If an image has a single channel, you can use a single number instead, e.g. Image.new("L", (1, 1), 255). For “F” mode images, floating point values are also accepted. In the case of “P” mode images, these will be indexes for the color ...
🌐
Real Python
realpython.com › image-processing-with-the-python-pillow-library
Image Processing With the Python Pillow Library – Real Python
January 8, 2025 - You create a new Image object from img_cat by using .point() and setting all values to zero. Next, you use the composite() function in PIL.Image to create an image made up from both img_cat and blank using cat_mask to determine which parts of ...
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › handbook › tutorial.html
Tutorial - Pillow (PIL Fork) 12.2.0 documentation
Using the Image class: The most important class in the Python Imaging Library is the Image class, defined in the module with the same name. You can create instances of this class in several ways; e...
🌐
GitHub
github.com › python-pillow › Pillow › blob › main › src › PIL › Image.py
Pillow/src/PIL/Image.py at main · python-pillow/Pillow
* :py:func:`~PIL.Image.new` * :py:func:`~PIL.Image.frombytes` """ · format: str | None = None · format_description: str | None = None · _close_exclusive_fp_after_loading = True · · def __init__(self) -> None: # FIXME: take "new" parameters / other image?
Author   python-pillow
🌐
Python Crash Course
ehmatthes.github.io › pcc_2e › beyond_pcc › pillow
Pillow - Working with Images - Python Crash Course, 2nd Edition
Then we call Image.new(), just like you saw earlier. We get an image that’s all black, with the dimensions we specified: To demonstrate a simple way to work with a blank canvas, we’ll set every pixel’s component value randomly: from random import randint from PIL import Image # Set a size and mode, and create a new image.
Find elsewhere
Top answer
1 of 1
2

You'll need to set up relative (label) coordinates and sizes (in cm) for all elements, you want to draw, and then calculate the corresponding image coordinates and sizes (in pixels) w.r.t. the desired resolution. That'll get somehow cumbersome, but I can't think of another way to do this independent of the resolution.

In the following, I left out the whole QR code thing to keep things at least a bit readable.

For comparison, your code as is (without the QR code thing) generates this image on my machine:

If I open that image in Photoshop, it says 9.7 cm x 7.2 cm at 72 dpi. If I calculate the resolutions by hand, I'll get the following results:

275 pixels / 7.5 cm * (2.54 cm/inch) = ca. 93 dpi
204 pixels / 5.5 cm * (2.54 cm/inch) = ca. 94 dpi

We'll need the 94 dpi later.

I approximated the relative (label) coordinates and sizes from your original image.

Now, first let's see the whole code:

from PIL import Image, ImageDraw, ImageFont

# Set up parameters
w_cm, h_cm = (7.5, 5.5)             # Real label size in cm
res_x, res_y = (300, 300)           # Desired resolution
res_y_old = 94                      # Old y resolution (204 / 5.5 * 2.54)

# Inch-to-cm factor
f = 2.54

# Determine image size w.r.t. resolution
w = int(w_cm / f * res_x)
h = int(h_cm / f * res_y)

# Create new image with proper size
img = Image.new('RGB', (w, h), color=(220, 220, 220))

# Draw elements
draw = ImageDraw.Draw(img)


def draw_text(x_cm, y_cm, font_size):
    font = ImageFont.truetype('arial.ttf', int(font_size / (res_y_old / res_y)))
    x, y = (int(x_cm / f * res_x), int(y_cm / f * res_y))
    draw.text((x, y), 'test', (0, 0, 0), font=font)


# Draw texts
draw_text(1.875, 4, 25)
draw_text(3.15, 3.25, 60)

# Polygon
coords_cm = [(0.15, 0.5), (1.35, 0.9), (1.35, 0.1)]
coords = [(int(c[0] / f * res_x), int(c[1] / f * res_y)) for c in coords_cm]
draw.polygon(tuple(coords), fill=(0, 0, 0))

# Save image
img.save('image.png', dpi=(res_x, res_y))

And, let's see the output:

If I open that image in Photoshop, it says 7.5 cm x 5.5 cm at 300 dpi, so exactly, what we wanted.

Regarding the font sizes: I guess, you set up those font sizes manually to get a certain appearance. Unfortunately, font sizes given in points are adjusted to have a certain height on monitors, but they won't scale for printing (or "printed" images). That's why, we need to scale the fonts w.r.t. the old and new resolution to keep the desired text appearance from your original image.

Everything else is repetitive converting relative coordinates and sizes. Do not hesitate to ask, if further explanations are needed!

----------------------------------------
System information
----------------------------------------
Platform:    Windows-10-10.0.16299-SP0
Python:      3.8.5
Pillow:      8.1.0
----------------------------------------
🌐
Pillow Documentation
pillow.readthedocs.io › en › stable › reference › ImageDraw.html
ImageDraw module - Pillow (PIL Fork) 12.2.0 documentation
The ImageDraw module provides simple 2D graphics for Image objects. You can use this module to create new images, annotate or retouch existing images, and to generate graphics on the fly for web use. For a more advanced drawing library for PIL, see the aggdraw module.
🌐
Pillow
pillow.readthedocs.io › en › latest › reference › Image.html
Image module - Pillow (PIL Fork) 12.3.0.dev0 documentation
The Image module provides a class with the same name which is used to represent a PIL image. The module also provides a number of factory functions, including functions to load images from files, and to create new images.
🌐
Wikipedia
en.wikipedia.org › wiki › Python_Imaging_Library
Python Imaging Library - Wikipedia
1 week ago - Python Imaging Library is a free and open-source additional library for the Python programming language that adds support for opening, manipulating, and saving many different image file formats. It is available for Windows, macOS and Linux. The latest version of PIL is 1.1.7, was released in ...
🌐
HolyPython
holypython.com › home › python pil tutorial › how to create a new image with pil
How to Create a New Image with PIL | HolyPython.com
December 9, 2022 - Although using color names is practical and works perfectly fine, you might want to use more specific color for your new image. In this example, let’s create an image in RGBA mode and specify a bluish color with approximately 50% transparency. A bluish color can be created with a high value for B band of the RGBA channels. We’ll also use 127 for the A band which is roughly half of the full value 255. ... from PIL import Image new = Image.new(mode="RGBA", size=(1920,1080), color=(10,10,255,127)) new.show()
🌐
GeeksforGeeks
geeksforgeeks.org › python-pil-image-open-method
Python PIL | Image.open() method - GeeksforGeeks
September 9, 2024 - PIL is the Python Imaging Library which provides the python interpreter with image editing capabilities. Image.split() method is used to split the image into individual bands. This method returns a tuple of individual image bands from an image. Splitting an “RGB” image creates three new images each
🌐
Neptune.ai
neptune.ai › blog › pil-image-tutorial-for-machine-learning
Essential Pil (Pillow) Image Tutorial (For Machine Learning ...
Piotr Niedźwiedź, founder and CEO of Neptune, said, “This is an exciting step for us. We’ve always believed that good tools help researchers do their best work. Joining OpenAI gives us the chance to bring that belief to a new scale.”
🌐
Bitbucket
hhsprings.bitbucket.io › docs › programming › examples › python › PIL › Image__class_Image.html
Image Module - class Image — Pillow (PIL) examples
>>> # from bytes >>> from PIL import Image >>> >>> rawpixelbytes = b'\xa0\xfe\xfe\xa0' >>> >>> # with frombytes >>> img1 = Image.frombytes("L", (2, 2), rawpixelbytes) >>> >>> # putdata after new >>> img2 = Image.new("L", (2, 2)) >>> img2.putdata(rawpixelbytes) >>> >>> # identical?
🌐
PyPI
pypi.org › project › pillow
pillow · PyPI
It should provide a solid foundation for a general image processing tool. ... To report a security vulnerability, please follow the procedure described in the Tidelift security policy. ... Download the file for your platform. If you're not sure which to choose, learn more about installing packages. ... Filter files by name, interpreter, ABI, and platform. If you're not sure about the file name format, learn more about wheel file names. ... pillow-12.2.0-pp311-pypy311_pp73-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (6.0 MB view details)
      » pip install pillow
    
Published   Apr 01, 2026
Version   12.2.0
🌐
Omz Software
omz-software.com › pythonista › docs › ios › Image.html
The Image Module — Python 3.6.1 documentation
February 19, 2020 - Creates a new image with the given size, and the same mode as the original, and copies data to the new image using the given transform. In the current version of PIL, the method argument can be EXTENT (cut out a rectangular subregion), AFFINE (affine transform), QUAD (map a quadrilateral to ...