Jump to content

Merging images while preserving transparency


Tyilo

Recommended Posts

I have tried many solution, but nothing seems to fix this.

The problem is that i put an image with transparency on top of another image, but the transparent pixels still transparent, where they should show some of the image below it.

 

If you call it with l=100 and p=20 i would get this result http://cl.ly/566Z instead of this http://cl.ly/56OF.

 

Here is the source code and I have attached the images:

<?php
header('Content-type: image/png');
echo imagepng(progressbar($_GET['l'], $_GET['p']));
function progressbar($length, $percentage)
{
$length = round($length / 2) * 2;
$percentage = min(100, max(0, $percentage));
if($length > 0)
{
	$bar = imagecreate($length, 14);
	imagealphablending($bar, false);
	imagesavealpha($bar, true);
	$empty = imagecreatefrompng('Empty.png');
	imagealphablending($empty, false);
	imagesavealpha($empty, true);
	$fill = imagecreatefrompng('Fill.png');
	imagealphablending($fill, false);
	imagesavealpha($fill, true);
	$lempty = imagecreatefrompng('LeftEmpty.png');
	imagealphablending($lempty, false);
	imagesavealpha($lempty, true);
	$lfill = imagecreatefrompng('LeftFill.png');
	imagealphablending($lfill, false);
	imagesavealpha($lfill, true);
	$rempty = imagecreatefrompng('RightEmpty.png');
	imagealphablending($rempty, false);
	imagesavealpha($rempty, true);
	$rfill = imagecreatefrompng('RightFill.png');
	imagealphablending($rfill, false);
	imagesavealpha($rfill, true);
	$emptycaplength = min(7, $length / 2); //5 
	imagecopy($bar, $lempty, 0, 0, 0, 0, $emptycaplength, 14);
	imagecopy($bar, $rempty, $length - $emptycaplength, 0, 7 - $emptycaplength, 0, $emptycaplength, 14);
	if($length > 14)
	{
		imagecopyresized($bar, $empty, 7, 0, 0, 0, $length - 14, 14, 1, 14);
	}
	$filllength = round(($length * ($percentage / 100)) / 2) * 2;
	$fillcaplength = min(7, $filllength / 2);
	imagecopy($bar, $lfill, 0, 0, 0, 0, $fillcaplength, 14);
	imagecopy($bar, $rfill, $filllength - $fillcaplength, 0, 7 - $fillcaplength, 0, $fillcaplength, 14);
	if($filllength > 14)
	{
		imagecopyresized($bar, $fill, 7, 0, 0, 0, $filllength - 14, 14, 1, 14);
	}
	imagealphablending($bar, true);
	return $bar;
}
else
{
	return false;
}
}
?>

 

[attachment deleted by admin]

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.