php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #36218 weird behaviour using imagecolorallocate very often
Submitted: 2006-01-30 23:46 UTC Modified: 2006-01-31 00:11 UTC
From: jumo at gmx dot de Assigned:
Status: Not a bug Package: GD related
PHP Version: 5.1.2 OS: debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jumo at gmx dot de
New email:
PHP Version: OS:

 

 [2006-01-30 23:46 UTC] jumo at gmx dot de
Description:
------------
I want to draw many squares on a PNG image, wich have changing color.

after some correct drawed there is only one color used.

Reproduce code:
---------------
<?php 

$bigsize 	= 500;

$colours	= array( 'FF0000' , '00FF00' );

header("Content-type: image/png");
$im 	= imagecreate( $bigsize * 2 , 50 );

for( $j = 0; $j < $bigsize ; $j++ ) {

	$k	= $j % count( $colours );
	$r	= hexdec( substr( $colours[ $k ] , 0 , 2 ) );
	$g	= hexdec( substr( $colours[ $k ] , 2 , 2 ) );
	$b	= hexdec( substr( $colours[ $k ] , 4 , 2 ) );
	$fill	= imagecolorallocate($im, $r , $g , $b );
	imagefilledrectangle( $im , 2*$j , 0 , 2*$j+1 , 50 , $fill );

}

imagepng($im);
imagedestroy($im);

?>

Expected result:
----------------
a bar with red and green vertical stripes wich have changing colors.

Actual result:
--------------
the right half of the bar is green.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-30 23:54 UTC] jumo at gmx dot de
excuse my bad english!
 [2006-01-31 00:11 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You're alway allocating a new color to a palette based 
image. Either register just the colors you use or create 
the image using imagecreatetruecolor() 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 10:01:29 2025 UTC