php / php/php-src

Bug on colors when loading bitmap file

Open
#11,442 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: gd Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

Hello,

On some bitmap files, i saw that the color of pixels got with imagecreatefrombmp/imagecolorat/imagecolorsforindex are not the correct one.

To reproduce the issue, just load the image in attachment :

$bmp = imagecreatefrombmp($bitmapFilePath);

then read the color of the pixel in 0,0 :

$rgb = imagecolorat($bmp, 0, 0);
$px = imagecolorsforindex($bmp, $rgb);

You will have the color 0, 248, 0 (green) but the color should be 255,0,255 (magenta).

The bitmap file is correctly displayed on my OS (ubuntu) and in gimp software.

bg1.zip

Here is my php version :

PHP 8.1.2-1ubuntu2.11 (cli) (built: Feb 22 2023 22:56:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2-1ubuntu2.11, Copyright (c), by Zend Technologies
PHP Version

8.1.2

Operating System

Ubuntu 22.04.2 LTS

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the report with the attached bg1.zip file using imagecreatefrombmp(), then inspect the values returned by imagecolorat() and imagecolorsforindex() for pixel 0,0. Trace the bitmap-loading path from these entry points and compare the observed RGB values with the expected magenta value; done means the reported bitmap color is decoded correctly.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.