php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40801 imagecolorat works incorrectly with imagecreatefromgif and imagecreatefrompng
Submitted: 2007-03-14 09:53 UTC Modified: 2007-03-14 11:00 UTC
From: belkovich at yandex dot ru Assigned:
Status: Not a bug Package: GD related
PHP Version: 5.2.1 OS: Win XP Pro
Private report: No CVE-ID: None
 [2007-03-14 09:53 UTC] belkovich at yandex dot ru
Description:
------------
Hello

imagecolorat works incorrectly with imagecreatefromgif and imagecreatefrompng
and it works with imagecreatefromjpeg

Here is working code:
<?php
$im = imagecreatefromjpeg("Capture.jpg");

$rgb = imagecolorat($im,10,10);

echo $rgb;

$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

echo $r."_".$g."_".$b;

?> 


Sincerely,
Dmitry


Reproduce code:
---------------
<?php
$im = imagecreatefromgif("Capture.gif");

$rgb = imagecolorat($im,10,10);

echo $rgb;

$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

echo $r."_".$g."_".$b;

?> 


Expected result:
----------------
255_255_255 on white color, when use imagecolorat with jpg


Actual result:
--------------
0_0_106 on white color, when use PNG imagecreatefrompng) or imagecreatefromgif(with GIF  file)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-03-14 09:59 UTC] tony2001@php.net
Put those images online, so we can actually use your code to reproduce it (without the pictures it's useless).
 [2007-03-14 11:00 UTC] pajoye@php.net
imagecolorat returns the color index (position in the palette) for palette based image or the color value for true color images.

imagecreatefromjpeg creates true color images, always. imagecreatefromgif creates always palette based images and imagecreatefrompng creates either palette or true color images as PNG supports both image types.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Nov 10 05:01:28 2024 UTC