hello i am doing png image cropping using this function. every thing is working fine. but whenever i was uploaded .png then changing the image background color into black. here is the code.my problem is image quality. getting balck color in background of the image . - $bgimage_attribs = getimagesize($bgim_file_name);
-
-
if($filetype3=='image/gif')
-
{
-
$bgim_old = imagecreatefromgif($bgim_file_name);
-
}
-
else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))
-
{
-
$bgim_old = imagecreatefromjpeg($bgim_file_name);
-
}
-
else if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
-
{
-
$bgim_old = imagecreatefrompng($bgim_file_name);
-
}
-
-
$bgth_max_width =265; //for Album image
-
$bgth_max_height =150;
-
$bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
-
-
$bgth_width =265;//$image_attribs[0] * $ratio;
-
$bgth_height =150;//$image_attribs[1] * $ratio;
-
-
$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height);
-
imageantialias($bgim_new,true);
-
$bgth_file_name = "partners_logs/250x150/$Attachments3";
-
imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
-
if($filetype3=='image/gif')
-
{
-
imagegif($bgim_new,$bgth_file_name,100);
-
//$bgim_old = imagegif($bgim_file_name);
-
}
-
else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))
-
{
-
imagejpeg($bgim_new,$bgth_file_name,100);
-
}
-
else if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
-
{
-
imagepng($bgim_new,$bgth_file_name,9);
-
}
you didnt add those line anywhere?
you have used imagecolorallocate function but you didnt receive the returned value.
you need to receive the returned value and must have to fill all the background with that returned value
6 3274
before line 26 you need to fill up the background of your $bgim_new. otherwise by default the background is BLACK
tryed like this also but no use. - /************************************Resizing the image 80*60****************/
-
$path3="partners_logs";
-
$filetype3=$_FILES["pimage"]["type"];
-
$bgim_file_name = $path3."/".$Attachments2;
-
$bgimage_attribs = getimagesize($bgim_file_name);
-
-
if($filetype3=='image/gif')
-
{
-
$bgim_old = imagecreatefromgif($bgim_file_name);
-
}
-
else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))
-
{
-
$bgim_old = imagecreatefromjpeg($bgim_file_name);
-
}
-
else if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
-
{
-
$bgim_old = imagecreatefrompng($bgim_file_name);
-
-
}
-
-
$bgth_max_width =265; //for Album image
-
$bgth_max_height =150;
-
$bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
-
-
$bgth_width =265;//$image_attribs[0] * $ratio;
-
$bgth_height =150;//$image_attribs[1] * $ratio;
-
-
$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height);
-
imageantialias($bgim_new,true);
-
if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
-
{
-
imagecolorallocate($bgim_new,0xFF,0xFF,0xFF);
-
}
-
$bgth_file_name = "partners_logs/250x150/$Attachments2";
-
imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
-
if($filetype3=='image/gif')
-
{
-
imagegif($bgim_new,$bgth_file_name,100);
-
//$bgim_old = imagegif($bgim_file_name);
-
}
-
else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))
-
{
-
imagejpeg($bgim_new,$bgth_file_name,100);
-
}
-
else if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
-
{
-
-
imagepng($bgim_new,$bgth_file_name,9);
-
//set the background color to your choice, paramters are int values of red,green and blue
-
-
}
-
/************End Resize of 80*60*******************/
try to add this line after line 28(in the post) -
-
$white = imagecolorallocate($bgim_new, 255, 255, 255); //FOR WHITE BACKGROUND
-
imagefilledrectangle($bgim_new,0,0,$bgth_width,$bgth_height,$white);
-
still getting same black color
here this is my full page. upload png once see what is going on? - <?
-
if(is_uploaded_file($_FILES["pimage"]["tmp_name"])!='')
-
{
-
//echo"file in";exit;
-
//echo"in ";exit;
-
$rand_variable1=rand(10000,100000);
-
if(is_uploaded_file($_FILES["pimage"]["tmp_name"]))
-
{
-
if($hidden_image!="")
-
{
-
-
@unlink("partners_logs/".$hidden_image);
-
@unlink("partners_logs/250x150/".$hidden_image);
-
-
}
-
$file_image13=$rand_variable1.$_FILES["pimage"]["name"];
-
move_uploaded_file($_FILES["pimage"]["tmp_name"], "partners_logs/".$file_image13);
-
-
$Attachments3=$file_image13;
-
-
}
-
/************************************Resizing the image 80*60****************/
-
$path3="partners_logs";
-
$filetype3=$_FILES["pimage"]["type"];
-
$bgim_file_name = $path3."/".$Attachments3;
-
$bgimage_attribs = getimagesize($bgim_file_name);
-
-
if($filetype3=='image/gif')
-
{
-
$bgim_old = imagecreatefromgif($bgim_file_name);
-
}
-
else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))
-
{
-
$bgim_old = imagecreatefromjpeg($bgim_file_name);
-
}
-
else if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
-
{
-
$bgim_old = imagecreatefrompng($bgim_file_name);
-
imageAlphaBlending($bgim_old, true);
-
imageSaveAlpha($bgim_old, true);
-
}
-
-
$bgth_max_width =265; //for Album image
-
$bgth_max_height =150;
-
$bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
-
-
$bgth_width =265;//$image_attribs[0] * $ratio;
-
$bgth_height =150;//$image_attribs[1] * $ratio;
-
-
$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height);
-
imageantialias($bgim_new,true);
-
$bgth_file_name = "partners_logs/250x150/$Attachments3";
-
imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
-
if($filetype3=='image/gif')
-
{
-
imagegif($bgim_new,$bgth_file_name,100);
-
//$bgim_old = imagegif($bgim_file_name);
-
}
-
else if(($filetype3=='image/pjpeg') || ($filetype3=='image/jpeg'))
-
{
-
imagejpeg($bgim_new,$bgth_file_name,100);
-
}
-
else if(($filetype3=='image/png') || ($filetype3=='image/x-png'))
-
{
-
imagepng($bgim_new,$bgth_file_name,9);
-
//set the background color to your choice, paramters are int values of red,green and blue
-
imagecolorallocate($bgim_new,0xFF,0xFF,0xFF);
-
}
-
/************End Resize of 80*60*******************/
-
-
}
-
else
-
{
-
//echo"file out";exit;
-
$Attachments3=$hidden_image;
-
}
-
?>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<title>Untitled Document</title>
-
</head>
-
-
<body>
-
<form name="UserDetails" action="" method="post" enctype="multipart/form-data" onSubmit="return checkValid(this);">
-
<input type="hidden" name="new_action" value="<?=$act?>">
-
<input type="hidden" name="new_start" value="<?=$start?>">
-
<? if($act == 'edit'){
-
$qUsers = "SELECT * FROM partners WHERE auto_id = $id";
-
$rsUsers = getSqlQuery($qUsers);
-
$resUsers = getSqlFetch($rsUsers);
-
extract($resUsers);
-
?>
-
<input type="hidden" name="edit_id" value="<?=$id?>">
-
<? }?>
-
<table width="50%" border="0" cellspacing="0" cellpadding="4">
-
<? if($errMsg == 1){?>
-
<tr align="center">
-
<td colspan="5" align="center" valign="middle"><FONT color=red>Admin Name already exist! Please try again.</FONT></td>
-
</tr>
-
<? }?>
-
-
-
-
<tr align="center">
-
<td> </td>
-
<td align="left">Company Logo</td>
-
<td><strong>:</strong></td>
-
<td align="left"><input type="file" name="pimage" >
-
<input type="hidden" name="hidden_image" value="<?php echo $images ?>" ></td>
-
<td> </td>
-
</tr>
-
<? if($images!="")
-
{ ?>
-
<tr align="center">
-
<td> </td>
-
<td align="left">Company Logo</td>
-
<td><strong>:</strong></td>
-
<td align="left"><img src="partners_logs/250x150/<?php echo $images ?>"></td>
-
<td> </td>
-
</tr>
-
<? }?>
-
-
-
<tr align="center">
-
<td width="5%" height="1"> </td>
-
<td width="29%" height="1" align="left"> </td>
-
<td width="3%" height="1"> </td>
-
<td width="58%" height="1"> </td>
-
<td width="5%" height="1"> </td>
-
</tr>
-
<tr>
-
<td height="20" colspan="4" align="right">
-
<input type="submit" name=submit value="submit">
-
<!--<input name="Submit" type="submit" class="but" id="Submit" value="Submit">-->
-
<!--<input name="Reset" type="reset" class="but" id="Submit" value="Reset">-->
-
-
<!--<input name="Button" type="button" class="but" id="Submit" value="Cancel" onClick="history.back();">--> </td>
-
<td height="20" align="right"> </td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
</html>
you didnt add those line anywhere?
you have used imagecolorallocate function but you didnt receive the returned value.
you need to receive the returned value and must have to fill all the background with that returned value
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kevin Smith |
last post by:
Is there a way to "auto-crop" an image in PIL? I have some PNG images
with white backgrounds that I want cropped to show only the non-white...
|
by: J. VerSchave |
last post by:
I have a bunch of images that are
600x800
800x600
640x480
480x640
I want to use HTML to contrain the size of these images. I basically...
|
by: Paul E Collins |
last post by:
I need to load a bitmap image, crop it, and save it.
By cropping, I don't mean resizing - I mean reducing it to a fixed size
area.
Image img =...
|
by: ACaunter |
last post by:
Hi there,
I was wondering if there was a way to crop a peice of an ASP.Net Image,
allowing the user to zoom in on only a section of the picture??
...
|
by: Mark Denardo |
last post by:
Hi, I need some expert GDI+ person to help me with my RoundOffImage
Function:
What I'm trying to do is take in an image, crop off the edges...
|
by: zacariaz |
last post by:
I dont know, and i dont much like javascript, however, i am told that
the only way to do want i want to do, is with javascript, so here goes.
...
|
by: Poppa Pimp |
last post by:
ImageResizer.php
Image Resizer PLEASE HELP
The URL of the page this is on in my site is...
|
by: Ofir Picazo |
last post by:
Hello everyone,
I'm trying to crop a polygon (defined as an array of coordinates) from
a larger image. I read lots about gd and imagick but...
|
by: sampath nslabs |
last post by:
sir
How to crop the image in visual basic 6.0.iam geting in vb.net but i want purelly in vb.plese give the code for that or give me useful...
|
by: koyanpaing |
last post by:
Hello everyone,
I am using image cropping tools moocrop for cropping image.
I would like to know the meaning of
crop5.addEvent('onDblClk',...
|
by: better678 |
last post by:
Question:
Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct?
Answer:
Java is an object-oriented...
|
by: teenabhardwaj |
last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
|
by: Matthew3360 |
last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function.
Here is my code.
...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
|
by: Oralloy |
last post by:
Hello Folks,
I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA.
My problem (spelled failure) is with the...
|
by: Carina712 |
last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
| |