Skip to content

RGB/BGR confusion #9049

@ubitux

Description

@ubitux

What did you do?

import sys
from PIL import Image

i = Image.open(sys.argv[1])
o = Image.new(mode="RGB", size=i.size)
o.putdata([r << 16 | g << 8 | b for r, g, b in i.getdata()])
o.save(sys.argv[2])

What did you expect to happen?

I expected this to have the input and output identical (normal case, no transparency etc)

What actually happened?

The output seems to expect BGR pixel format data, not RGB. I don't know if it's a bug or a documentation issue here. If this is expected, the doc probably needs some clarification about endianness and actual memory layout expected.

What are your OS, Python and Pillow versions?

  • OS: Linux x86_64
  • Python: 3.13.3
  • Pillow: 11.2.1
--------------------------------------------------------------------
Pillow 11.2.1
Python 3.13.3 (main, Apr  9 2025, 07:44:25) [GCC 14.2.1 20250207]
--------------------------------------------------------------------
Python executable is /usr/bin/python3
System Python files loaded from /usr
--------------------------------------------------------------------
Python Pillow modules loaded from /usr/lib/python3.13/site-packages/PIL
Binary Pillow modules loaded from /usr/lib/python3.13/site-packages/PIL
--------------------------------------------------------------------
--- PIL CORE support ok, compiled for 11.2.1
--- TKINTER support ok, loaded 8.6
--- FREETYPE2 support ok, loaded 2.13.3
--- LITTLECMS2 support ok, loaded 2.17
--- WEBP support ok, loaded 1.5.0
*** AVIF support not installed
--- JPEG support ok, compiled for libjpeg-turbo 3.1.0
--- OPENJPEG (JPEG2000) support ok, loaded 2.5.3
--- ZLIB (PNG/ZIP) support ok, loaded 1.3.1
--- LIBTIFF support ok, loaded 4.7.0
--- RAQM (Bidirectional Text) support ok, loaded 0.10.2
--- LIBIMAGEQUANT (Quantization method) support ok, loaded 4.2.2
--- XCB (X protocol) support ok
--------------------------------------------------------------------

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions