php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39314 imagecolorallocatealpha causing problems
Submitted: 2006-10-31 02:50 UTC Modified: 2006-11-01 13:36 UTC
From: slyc6 at aol dot com Assigned: pajoye (profile)
Status: Not a bug Package: *General Issues
PHP Version: 5.1.6 OS: Windows XP
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: slyc6 at aol dot com
New email:
PHP Version: OS:

 

 [2006-10-31 02:50 UTC] slyc6 at aol dot com
Description:
------------
Ok the problem is that when you use imagesetpixel in an nested loop it fails to draw the specified pixel. Im trying to make an image mask and need imagecolorallocatealpha to change according to the mask image im using. But in this case i just simply set it to a grey color and an alpha value of 63. But anyway when I run this loop the image draws the pixels up to a certain point. Usually it stops on the second line 1/3 of the way. 

The way I fixed this porblem was taking imagecolorallocatealpha out of the nested loop and put it in the first loop. In my code I have a for loop using $x nested inside of for loop using $y. So when imagecolorallocatealpha is in the loop of $y I get my problem. But if I move it to $x I dont any problems (but I can't achieve my goal)

Reproduce code:
---------------
<?php
$newim = imagecreate(238,226);
$tran = imagecolorallocate($newim,4,4,4);
imagefill($newim,0,0,$tran);
imagecolortransparent ($newim,$tran);
$maskcolor = 0;

for($y=0;$y<226;$y++)
{
	for($x=0;$x<238;$x++)
	{	
$maskcolor = imagecolorallocatealpha ($newim,0,0,0,63);		
imagesetpixel ($newim,$x,$y,$maskcolor);
	}
}
header("Content-type: image/png");
imagepng($newim);
?>



Expected result:
----------------
what it should doing is something along the lines of this
----------------------------------

xxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxx
etc...


Actual result:
--------------
but I get something like this
--------------------------

xxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxx

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-10-31 13:05 UTC] pajoye@php.net
You allocate a new color on each iteration. You reached the 255 limit on the 255th iteration.

It makes also little sense to do that in the loop if you use always the same color. As a side note, you may consider to use imagefill or imagefilledrectangle.
 [2006-10-31 16:05 UTC] slyc6 at aol dot com
Well I only use 63 for the example. But what Im  really trying to do is set a color ever pixel but the color differ in alpha value depending on  the color of the pixel in the image mask that I am using.

imagecolorallocatealpha ($newim,0,0,0,63);	
So when I really call this function it would be more along the lines of
imagecolorallocatealpha ($newim,$backr,$backg,$backb,$alpha);

So is there a way I can delete the previous color after I use it since I only need it for that one pixel? So I dont reach that 255 cap?
 [2006-11-01 13:36 UTC] pajoye@php.net
"Well I only use 63 for the example."

You try to use much colors:
for($y=0;$y<226;$y++)for($x=0;$x<238;$x++); <<!!

Imagecreate creates a palette based images. Palette based images use a 256 colors palette to store the colors used by the image. Each color has a unique index. The pixel uses this index to define which color to use.

use true color images, they have unlimited colors (nearly):
$im = imagecreatetruecolor(...);


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Dec 10 08:01:27 2024 UTC