Jump to content

Problems with imagecreatefrompng


noon

Recommended Posts

I'm pretty sure what the problem IS however I do not know how I can handle it well.  I have a function that uses imagecreatefrompng($im) and there is an issue with images and transparency.  Here is my code:

	$im = imagecreatefrompng('images/test/' . $image);

// Calculate how many grid squares needed
$yquad = (int) (imagesy($im) / 16);
$yquad += ((imagesy($im) % 16) > 0) ? 1 : 0;
$xquad = (int) (imagesx($im) / 16);
$xquad += ((imagesx($im) % 16) > 0) ? 1 : 0;

// # of pixels used.
// imagesx, imagesy not sufficient because it may not be
// an even multiple of 16
$row = $xquad*16;
$col = $yquad*16;

//	Generate grid squares
for ($y = 0; $y < $col; $y++)
{
	for ($x = 0; $x < $row; $x++)
	{
		$color = imagecolorat($im,$x,$y);
		$a = ((int) ($x / 16)) + 1;
		$b = ((int) ($y / 16)) + 1;

		if ($color!=NULL)
			$grid[$a][$b] .= sprintf("#%'06X;", $color);
		else
			$grid[$a][$b] .= '#FFFFFF;';			
	}
}

 

I am capturing the color information at the given coordinates and converting it to hex.  The only way I could figure out to keep leading zeros is to use the '06 to specify padding of 6 and fill character of 0.  If I have a PNG with transparency, my result is drastically wrong (either blue or red tint to it).  The only fix I have is to open up a graphics editor (im using GIMP) and copy -> paste into a new file with background contents as white.  Even when I tried using IrfanView and saving with save transparency unchecked I get the tint.  How can I solve this?

 

PS - Taking off the padding results in a lot of two character hex values (eg #76;) and not longer than 6 character results.

Link to comment
https://forums.phpfreaks.com/topic/64694-problems-with-imagecreatefrompng/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.