-1

i have to crop images. but i have code to crop images. but .png files are not cropping that code. i have to crop .png image files. plz any one help me.

2
Contributors
7
Replies
8
Views
7 Years
Discussion Span
Last Post by venkat0904
1

may be ur code is using GD extension which i guess is not enabled in ur php.ini
GD is used for image processing.
u r facing problem only with png images or with jpegs too?
wy dont u let us have a look on the code...

i have to crop images. but i have code to crop images. but .png files are not cropping that code. i have to crop .png image files. plz any one help me.

0

sorry.....all files are uploading. but i am croping that files . .jpeg files are croping but the only problem with .png files.
"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 114" .
above error occuring. have you any code to crop images?

0

okkk if its working with jpegs den the prob shud not b with GD.
Do lemme know if u really want to crop images or just create thumbnails for them? I have a thumbnail creation code in handy...

sorry.....all files are uploading. but i am croping that files . .jpeg files are croping but the only problem with .png files.
"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 114" .
above error occuring. have you any code to crop images?

-1

okkk if its working with jpegs den the prob shud not b with GD.
Do lemme know if u really want to crop images or just create thumbnails for them? I have a thumbnail creation code in handy...

yes. exactly. plz....send me that code. and also verymuch thanks to ur replys

0

Here's the code i use for thumbnail creation in my application. Works like a charm for me.. let me know if u have some problems using it..
And remember to mark the thread as solved once u r done..

/*
	Function createthumb($name,$filename,$new_w,$new_h)
	creates a resized image
	variables:
	$name		Original filename
	$filename	Filename of the resized image
	$new_w		width of resized image
	$new_h		height of resized image
*/	
function createthumb($name,$filename,$new_w,$new_h)
{
	$system=explode(".",$name);
	if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
	if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
	if (preg_match("/gif/",$system[1])){$src_img=imagecreatefromgif($name);}
	$old_x=imageSX($src_img);
	$old_y=imageSY($src_img);
	if ($old_x > $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$old_y*($new_h/$old_x);
	}
	if ($old_x < $old_y) 
	{
		$thumb_w=$old_x*($new_w/$old_y);
		$thumb_h=$new_h;
	}
	if ($old_x == $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$new_h;
	}
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
	if (preg_match("/png/",$system[1])){
		imagepng($dst_img,$filename); 
                } elseif (preg_match("/gif/",$system[1]))  {
		imagegif($dst_img,$filename);
	} else {
		imagejpeg($dst_img,$filename); 
	}
	imagedestroy($dst_img); 
	imagedestroy($src_img); 
}

yes. exactly. plz....send me that code. and also verymuch thanks to ur replys

-1

Here's the code i use for thumbnail creation in my application. Works like a charm for me.. let me know if u have some problems using it..
And remember to mark the thread as solved once u r done..

/*
	Function createthumb($name,$filename,$new_w,$new_h)
	creates a resized image
	variables:
	$name		Original filename
	$filename	Filename of the resized image
	$new_w		width of resized image
	$new_h		height of resized image
*/	
function createthumb($name,$filename,$new_w,$new_h)
{
	$system=explode(".",$name);
	if (preg_match("/jpg|jpeg/",$system[1])){$src_img=imagecreatefromjpeg($name);}
	if (preg_match("/png/",$system[1])){$src_img=imagecreatefrompng($name);}
	if (preg_match("/gif/",$system[1])){$src_img=imagecreatefromgif($name);}
	$old_x=imageSX($src_img);
	$old_y=imageSY($src_img);
	if ($old_x > $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$old_y*($new_h/$old_x);
	}
	if ($old_x < $old_y) 
	{
		$thumb_w=$old_x*($new_w/$old_y);
		$thumb_h=$new_h;
	}
	if ($old_x == $old_y) 
	{
		$thumb_w=$new_w;
		$thumb_h=$new_h;
	}
	$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
	imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); 
	if (preg_match("/png/",$system[1])){
		imagepng($dst_img,$filename); 
                } elseif (preg_match("/gif/",$system[1]))  {
		imagegif($dst_img,$filename);
	} else {
		imagejpeg($dst_img,$filename); 
	}
	imagedestroy($dst_img); 
	imagedestroy($src_img); 
}

where you assigning new width ,height.?

0

u can pass them as parameters to the function as $new_w, $new_h
the function will create a thumbnail maintaining the same aspect ratio as the original image..

where you assigning new width ,height.?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.