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]

Link to comment
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.