Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.