Jump to content

php gd transparency issue


bahearn

Recommended Posts

This is my script currently it uploads and re sizes images but when i try to upload and re size png, gif with transparent backgrounds the background color becomes black and is not transparent any ideas ?

 

if($_SERVER["REQUEST_METHOD"] == "POST")
{

$image2 =$_FILES["file2"]["name"];
$uploadedfile2 = $_FILES['file2']['tmp_name'];

	if ($image2) 
	{

	$filename2= stripslashes($_FILES['file2']['name']);
	$extension2 = getExtension($filename2);
	$extension2 = strtolower($extension2);

if (($extension2 != "jpg") && ($extension2 != "jpeg") && ($extension2 != "png") && ($extension2 != "gif")) 
		{
			$change='<div class="msgdiv">Unknown Image extension </div> ';
			$errors=1;
		}
		else
		{
$size2=filesize($_FILES['file2']['tmp_name']);
if ($size2> MAX_SIZE*2048)
{
$change='<div class="msgdiv">You have exceeded the size limit!</div> ';
$errors=1;
}
if($extension2 =="jpg" || $extension2 == "jpeg")
{
$uploadedfile2 = $_FILES['file2']['tmp_name'];
$src2 = imagecreatefromjpeg($uploadedfile2);
}
else if($extension2 =="png")
{
$uploadedfile2 = $_FILES['file2']['tmp_name'];
$src2 = imagecreatefrompng($uploadedfile2);
}
else 
{
$src2 = imagecreatefromgif($uploadedfile2);
}
list($width2,$height2)=getimagesize($uploadedfile2);
$newwidth2=1024;
$newheight2=768;
$tmp2=imagecreatetruecolor($newwidth2,$newheight2);
imagecopyresampled($tmp2,$src2,0,0,0,0,$newwidth2,$newheight2,$width2,$height2);
$filename2 = "images/". $_FILES['file2']['name'];
imagejpeg($tmp2,$filename2,100);
$finished = "<font color=\"red\">Great, your files have been uploaded</font>";
}}
}
//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors) 
{

}

Link to comment
https://forums.phpfreaks.com/topic/168149-php-gd-transparency-issue/
Share on other sites

Thanks, but it appears that on the server the actual created image file with my script loses the transparent background and changes to black, it is not an issue of showing the file as I am loading it into flash and flash will load transparent images correctly.

thanks,

ba

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.