Skip to content

Conversation

@radarhere
Copy link
Member

@radarhere radarhere commented Jul 12, 2025

When opening IPTC images at the moment, self._mode might be set to a single channel from RGB or CMYK.

elif layers == 3 and component:
self._mode = "RGB"[id]
elif layers == 4 and component:
self._mode = "CMYK"[id]

That's incorrect, as we don't have R, G, B, C, M, Y or K modes. Your first instinct might be to say that these should be the rawmode instead, but IptcImagePlugin just passes the image data on to be opened by another plugin. Instead, this PR uses Image.merge() to combine the image with empty bands for the other channels, to make up the full mode.

I've also made some simplifications.

def _i8(c: int | bytes) -> int:
return c if isinstance(c, int) else c[0]
is unused since 0a29d63, and so can be removed, and codec is always "iptc", so we don't have to check it.
ImageFile._Tile("iptc", (0, 0) + self.size, offset, compression)
]
def load(self) -> Image.core.PixelAccess | None:
if len(self.tile) != 1 or self.tile[0][0] != "iptc":

@radarhere radarhere force-pushed the iptc branch 2 times, most recently from d985411 to 23f2eac Compare July 12, 2025 04:29
@hugovk hugovk changed the title Fixed reading RGB and CMYK IPTC images Fix reading RGB and CMYK IPTC images Sep 4, 2025
@hugovk hugovk merged commit ae65315 into python-pillow:main Sep 4, 2025
57 checks passed
@radarhere radarhere deleted the iptc branch September 4, 2025 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants