hi all. i want to crop png image.
when i am croping the png image i got "Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in C:\wamp\www\taslan\admin\products.php on line 120" error message. at line no 120 shows imagepng($bgim_new,$bgth_file_name,100); this function

hi all. i want to crop png image.
when i am croping the png image i got "Fatal error: imagepng() [<a href='function.imagepng'>function.imagepng</a>]: gd-png: fatal libpng error: zlib error in C:\wamp\www\taslan\admin\products.php on line 120" error message. at line no 120 shows imagepng($bgim_new,$bgth_file_name,100); this function

The 3rd optional parameter to the imagepng() is called the quality and it specifies the compression level used.
It should have the value from 0 to 9 only, you used the much higher value for it :)

k. its working . but this function not supporting .bmp image files.
"

imagewbmp($bgim_new, $bgth_file_name,9);

" and also i put 100 like this

imagewbmp($bgim_new, $bgth_file_name,100);

still not working

Hey.

If you are having problems with functions, look them up in the manual.

The third parameter of the imagewbmp function is not the same as the third parameter for the png function. The manual explains the difference. Even gives examples.

k. its working . but this function not supporting .bmp image files.
"

imagewbmp($bgim_new, $bgth_file_name,9);

" and also i put 100 like this

imagewbmp($bgim_new, $bgth_file_name,100);

still not working

Its very natural if imagepng() doesn't suppport .bmp images.
and the imagewbmp() is not having the same parameters as like imagepng().
The 1st parameter to imagewbmp() is the image resource , 2nd is the file path and the 3rd is the forground color to be specified as the int value.The default value to it that of the black color.

The 3rd optional parameter to the imagepng() is called the quality and it specifies the compression level used.
It should have the value from 0 to 9 only, you used the much higher value for it :)

hello,


i am facing another problem with this. i used values between '0' to '9' then image background color is changing like black. what is alternative for this?

hello,


i am facing another problem with this. i used values between '0' to '9' then image background color is changing like black. what is alternative for this?

imagewbmp() sets the foreground color.
Look for setImageBackgroundColor() function of the Imagick.

imagewbmp() sets the foreground color.
Look for setImageBackgroundColor() function of the Imagick.

this is also one of the problem, before that i struck at imagepng(); method , i am getting croped png with black background . give me idea!!

imagewbmp() sets the foreground color.
Look for setImageBackgroundColor() function of the Imagick.

i didn't catch u. can expain clearly.

$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height); 
imageantialias($bgim_new,true); 
			$bgth_file_name = "productimages/140X150/$Attachments1";
			imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='image/X-PNG'))
				{
					 imagepng($bgim_new,$bgth_file_name,9);
				} 
				else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
				{
            imagewbmp($bgim_new, $bgth_file_name,$bgim_new);
            }

this my code. what wrong with my code. help me.

You are using the imagewbmp function incorrectly.

The third parameter of the imagewbmp function sets the foreground color of the image to a color created by the imagecolorallocate function.

Look at the third example in the manual. It shows how to correctly use the third parameter.

i didn't catch u. can expain clearly.

$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height); 
imageantialias($bgim_new,true); 
			$bgth_file_name = "productimages/140X150/$Attachments1";
			imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='image/X-PNG'))
				{
					 imagepng($bgim_new,$bgth_file_name,9);
				} 
				else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
				{
            imagewbmp($bgim_new, $bgth_file_name,$bgim_new);
            }

this my code. what wrong with my code. help me.

i get black background for the imagepng();. what hpnd with my code.

You are using the imagewbmp function incorrectly.

The third parameter of the imagewbmp function sets the foreground color of the image to a color created by the imagecolorallocate function.

Look at the third example in the manual. It shows how to correctly use the third parameter.

hi all, still i dont get the coorect answer

if(($filetype1=='image/gif') || ($filetype1=='image/GIF'))	
				{
					$bgim_old = imagecreatefromgif($bgim_file_name); 
				}	
			else if(($filetype1=='image/pjpeg') || ($filetype1=='image/jpeg') ||($filetype1=='image/PJPEG') || ($filetype1=='image/JPEG'))	
				{
					 $bgim_old = imagecreatefromjpeg($bgim_file_name);
				}
			  else	if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='image/X-PNG'))
				{
				
					 $bgim_old = imagecreatefrompng($bgim_file_name);
					// echo $filetype1;exit;
				}
				else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
				{
                $bgim_old = imagecreatefromwbmp($bgim_file_name);
                }
						
			$bgth_max_width = 140; //for Album image
			$bgth_max_height = 150;
			$bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
		
			$bgth_width = 140;//$image_attribs[0] * $ratio; 
			$bgth_height = 150;//$image_attribs[1] * $ratio;
		
			$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height); 
			$background = imagecolorallocate($bgim_new, 255, 255, 255);
			imageantialias($bgim_new,true); 
			$bgth_file_name = "productimages/140X150/$Attachments1";
			imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
			if(($filetype1=='image/gif') || ($filetype1=='image/GIF'))	
				{
				    imagegif($bgim_new,$bgth_file_name,100);
					//$bgim_old = imagegif($bgim_file_name); 
				}	
			else if(($filetype1=='image/pjpeg') || ($filetype1=='image/jpeg')||($filetype1=='image/PJPEG') || ($filetype1=='image/JPEG'))	
				{
					 imagejpeg($bgim_new,$bgth_file_name,100);
				}
			  else	if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='image/X-PNG'))
				{
					 imagepng($bgim_new,$bgth_file_name,9);
				} 
				else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
				{
				
            imagewbmp($bgim_new, $bgth_file_name,$background);
            }

this my crop image code. what is yhe wrong with my code.

hi all, still i dont get the coorect answer

if(($filetype1=='image/gif') || ($filetype1=='image/GIF'))	
				{
					$bgim_old = imagecreatefromgif($bgim_file_name); 
				}	
			else if(($filetype1=='image/pjpeg') || ($filetype1=='image/jpeg') ||($filetype1=='image/PJPEG') || ($filetype1=='image/JPEG'))	
				{
					 $bgim_old = imagecreatefromjpeg($bgim_file_name);
				}
			  else	if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='image/X-PNG'))
				{
				
					 $bgim_old = imagecreatefrompng($bgim_file_name);
					// echo $filetype1;exit;
				}
				else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
				{
                $bgim_old = imagecreatefromwbmp($bgim_file_name);
                }
						
			$bgth_max_width = 140; //for Album image
			$bgth_max_height = 150;
			$bgratio = ($bgwidth > $bgheight) ? $bgth_max_width/$bgimage_attribs[0] : $bgth_max_height/$bgimage_attribs[1];
		
			$bgth_width = 140;//$image_attribs[0] * $ratio; 
			$bgth_height = 150;//$image_attribs[1] * $ratio;
		
			$bgim_new = imagecreatetruecolor($bgth_width,$bgth_height); 
			$background = imagecolorallocate($bgim_new, 255, 255, 255);
			imageantialias($bgim_new,true); 
			$bgth_file_name = "productimages/140X150/$Attachments1";
			imagecopyresampled($bgim_new,$bgim_old,0,0,0,0,$bgth_width,$bgth_height, $bgimage_attribs[0], $bgimage_attribs[1]);
			if(($filetype1=='image/gif') || ($filetype1=='image/GIF'))	
				{
				    imagegif($bgim_new,$bgth_file_name,100);
					//$bgim_old = imagegif($bgim_file_name); 
				}	
			else if(($filetype1=='image/pjpeg') || ($filetype1=='image/jpeg')||($filetype1=='image/PJPEG') || ($filetype1=='image/JPEG'))	
				{
					 imagejpeg($bgim_new,$bgth_file_name,100);
				}
			  else	if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='image/X-PNG'))
				{
					 imagepng($bgim_new,$bgth_file_name,9);
				} 
				else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
				{
				
            imagewbmp($bgim_new, $bgth_file_name,$background);
            }

this my crop image code. what is yhe wrong with my code.

i tried this code. now i am nottalking about .wbmp files. i was tested only .png image file code, i think there image background color is getting black color. but actual image background color is not black. am i correct? are you also getting same black background ?

i get black background for the imagepng();. what hpnd with my code.

line11 the imagewbmp() functions takes the foreground color as the third parameter.
And the background color to the image after the imagepng() function -

if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='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,$red,$green,$blue);
} 
else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
{
//set the foreground color here
$foreground = '';
	imagewbmp($bgim_new, $bgth_file_name,$foreground);
}

line11 the imagewbmp() functions takes the foreground color as the third parameter.
And the background color to the image after the imagepng() function -

if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='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,$red,$green,$blue);
} 
else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
{
//set the foreground color here
$foreground = '';
	imagewbmp($bgim_new, $bgth_file_name,$foreground);
}

if(($filetype1=='image/png') || ($filetype1=='image/x-png') ||($filetype1=='image/PNG') || ($filetype1=='image/X-PNG'))
{
imagepng($bgim_new,$bgth_file_name,9);
$background = imagecolorallocate($bgim_new, 255, 255, 255);
}
else if(($filetype1 == "image/bmp") || ($filetype1 == "image/BMP"))
{
$foreground = '255';
imagewbmp($bgim_new, $bgth_file_name,$foreground);
}

. i put code above but i get balck background color for imagepng and i am geting for error

Warning: imagecreatefromwbmp() [function.imagecreatefromwbmp]: 'productimages/72032lena512.bmp' is not a valid WBMP file in C:\wamp\www\exampls\fileupload\uploadimage.php on line 38

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\wamp\www\exampls\fileupload\uploadimage.php on line 52

.
these two for imagewbmp(); what is the wrong.?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.