Skip to content

An LA image from Image.merge() or point() is pasted onto an RGB image as red #10524

Closed

Description

@jiren-the-gray

What did you do?

Built an LA image with Image.merge() (and with point()) and pasted it onto an RGB image with Image.paste() (code below).

What did you expect to happen?

A grey pixel, (128, 128, 128), as when the same LA image is converted with convert("RGB") or an LA image from Image.new() is pasted. Image.paste: "If the modes don't match, the pasted image is converted to the mode of this image (see the convert method for details)."

What actually happened?

new   (128, 128, 128)
merge (128, 0, 0)
point (128, 0, 0)
convert (128, 128, 128)

All three LA images report (128, 255) from getpixel(), but the merged and the point-mapped ones paste as red. Pillow 12.0.0 and main give the same output.

Possible cause: paste() does not convert LA onto RGB and copies the 4 stored bytes (Image.py#L1958-L1964), which assumes that LA is stored as L, L, L, A. Image.merge("LA", ...) stores L, 0, 0, A (Bands.c#L334-L341), and point() on an LA image leaves the middle bytes 0. #10510 describes the same difference in the middle bytes for getcolors(). With open PR #10511, Image.new("LA", ...) would store L, 0, 0, A as well, and pasting it onto RGB gives (128, 0, 0) on that branch.

What are your OS, Python and Pillow versions?

  • OS: Debian 12 in Docker (official Python image, Pillow wheel from PyPI) on Ubuntu 22.04.5, x86_64
  • Python: 3.12.16
  • Pillow: 13.0.0 (also 12.0.0 and main at a106f67)
--------------------------------------------------------------------
Pillow 13.0.0
Python 3.12.16 (main, Oct 28 2026, 02:01:35) [GCC 12.2.0]
--------------------------------------------------------------------
Python executable is /usr/local/bin/python3
System Python files loaded from /usr/local
--------------------------------------------------------------------
Python Pillow modules loaded from /usr/local/lib/python3.12/site-packages/PIL
Binary Pillow modules loaded from /usr/local/lib/python3.12/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 13.0.0
*** TKINTER support not installed
--- FREETYPE2 support ok, loaded 2.14.3
--- LITTLECMS2 support ok, loaded 2.19
--- WEBP support ok, loaded 1.6.0
--- AVIF support ok, loaded 1.4.2
--- JPEG support ok, compiled for libjpeg-turbo 3.2.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.4
--- ZLIB (PNG/ZIP) support ok, loaded 1.2.13, compiled for zlib-ng 2.3.3
--- LIBTIFF support ok, loaded 4.7.2
*** RAQM (Bidirectional Text) support not installed
*** LIBIMAGEQUANT (Quantization method) support not installed
--- XCB (X protocol) support ok
--------------------------------------------------------------------
from PIL import Image


def pasted(la):
    dst = Image.new("RGB", (1, 1))
    dst.paste(la, (0, 0))
    return dst.getpixel((0, 0))


new = Image.new("LA", (1, 1), (128, 255))
merged = Image.merge("LA", (Image.new("L", (1, 1), 128), Image.new("L", (1, 1), 255)))
pointed = new.point(lambda v: v)

print("new  ", pasted(new))
print("merge", pasted(merged))    # expected (128, 128, 128)
print("point", pasted(pointed))   # expected (128, 128, 128)
print("convert", merged.convert("RGB").getpixel((0, 0)))

AI disclosure

I used an AI assistant (Claude) to help find this issue and write this report. I ran the reproducer above and checked the output myself before filing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions