Jump to content

resize_image.php?image=detalj/d7_19.png PNG dont works.


Bengt7jqb

Recommended Posts

Hi,I am trying to have this to work with .png images too. JPG and GIF works just fine.Try it here on my test-site all pitures use this.

<?php//	*	*	*	*	*	*	*	*function MakeGif($name, $x, $y, $s, $a) {	$im  = imagecreate($x,$y); 	$bgc = imagecolorallocate($im, 200, 200, 200);	$tc  = imagecolorallocate($im, 255, 255, 255);	$tcd = imagecolorallocate($im, 0, 0, 0);	imagefilledrectangle($im, 0, 0, $x, $y, $bgc); 		/* Output an errmsg */	if ( function_exists('ImageFtText') ) 		{		if ( $a == 45 ) {			$tc  = imagecolorallocate($im, 241, 201, 241);			ImageFtText($im, $s, $a, 0, $y, $tcd, "./font/Timesbi.TTF", $name);			ImageFtText($im, $s, $a, 1, $y-1, $tc, "./font/Timesbi.TTF", $name);			}		else		if ( $y > $x ) {			ImageFtText($im, $s, 90, $x, $y, $tcd, "./font/Timesbi.TTF", $name);			ImageFtText($im, $s, 90, $x-1, $y-1, $tc, "./font/Timesbi.TTF", $name);			}		else			{			ImageFtText($im, $s, 0, 1, $y, $tcd, "./font/Timesbi.TTF", $name);			ImageFtText($im, $s, 0, 2, $y-2, $tc, "./font/Timesbi.TTF", $name);			}		}	else 		{		imagestring($im, 5, 2, 2, $name, $tcd);		imagestring($im, 5, 0, 0, $name, $tc);		}	imagecolortransparent($im,$bgc);	return $im;	}//	*	*	*	*	*	*	*	*$image = "galleri/".$_GET['image'];$size = GetImageSize($image);$width = $size[0];$height = $size[1];$dstimage = "./galleri/tn/".$image;	//  Not in use yeat$max_width = ($_GET['max_width']) ? $_GET['max_width'] : $size[0];$max_height = ($_GET['max_height']) ? $_GET['max_height'] : $size[1];$Q = ($_GET['q']) ? $_GET['q'] : 75;$wm = ($_GET['wm']) ? $_GET['wm'] : 'y';$x_ratio = $max_width / $width;$y_ratio = $max_height / $height;if ( ($width <= $max_width) && ($height <= $max_height) ) {	$tn_width = $width;	$tn_height = $height;	}elseif (($x_ratio * $height) < $max_height) {	$tn_height = ceil($x_ratio * $height);	$tn_width = $max_width;	}else 	{	$tn_width = ceil($y_ratio * $width);	$tn_height = $max_height;	}if ( strpos(strtolower($image), '.jpg') OR strpos(strtolower($image), '.jpeg') ) 	$src = ImageCreateFromJpeg($image);elseif ( strpos(strtolower($image), '.gif') ) 		$src = ImageCreateFromGif($image);elseif ( strpos(strtolower($image), '.png') ) 	// New part	$src = ImageCreateFrompng($image);if ( strpos(strtolower($image), '.jpg') OR strpos(strtolower($image), '.jpeg') OR strpos(strtolower($image), '.png') ) 	$dst = ImageCreateTrueColor($tn_width,$tn_height);elseif ( strpos(strtolower($image), '.gif') ) {	$dst = ImageCreate($tn_width,$tn_height);	$bgc = imagecolorallocate($dst, 255, 100, 255);	imagecolortransparent($dst,$bgc);	}imagecopyresampled($dst, $src, 0, 0, 0, 0,$tn_width,$tn_height,$width,$height);if ( $wm == 'y' ) {	  //  Add watermark	$Main_Image_width = imageSX($dst);	$Main_Image_height = imageSY($dst);	$WaterMark_Transparency = "60";	if ( $Main_Image_width > 150 )		$WaterMark = MakeGif("© www.radiomuseum.se",130,11,9,0);	else	if ( $Main_Image_height > 150 )		$WaterMark = MakeGif("© www.radiomuseum.se",11,130,9,90);	else		$WaterMark = MakeGif("© radiomuseum.se",100,11,9,0);	$WaterMark_width = imageSX($WaterMark);	$WaterMark_height = imageSY($WaterMark);	$MaterMark_x = ($Main_Image_width - $WaterMark_width)-6;	$MaterMark_y = ($Main_Image_height - $WaterMark_height)-6;	if ( $WaterMark_width < $Main_Image_width )		imageCopyMerge($dst, $WaterMark, $MaterMark_x, $MaterMark_y, 0, 0, $WaterMark_width, $WaterMark_height, $WaterMark_Transparency);	}if ( strpos(strtolower($image), '.jpg') OR strpos(strtolower($image), '.jpeg') ) {	header('Content-type: image/jpeg');	ImageJpeg($dst, null, $Q);	}elseif ( strpos(strtolower($image), '.gif') ) {	header('Content-type: image/gif');	ImageGif($dst, null, $Q);	}elseif ( strpos(strtolower($image), '.png') ) {	// New part	header('Content-type: image/png');	imagepng($dst, null, $Q);	}ImageDestroy($src);ImageDestroy($dst);if ( $wm ) ImageDestroy($WaterMark);?>

Any idea? Please!

Link to comment
Share on other sites

What happens when you use a PNG file?
Hi, I got an empty picture 0x0 pic small 33 byte :-)And I found the error in the bottom part
header('Content-type: '.$mime);switch ( $type ) {	case IMAGETYPE_JPEG:	ImageJpeg($dst, null, $Q);	break;	case IMAGETYPE_GIF:		ImageGif($dst);				break;	case IMAGETYPE_PNG:		imagepng($dst);				break;	default:  trigger_error('Failed resize image!', E_USER_WARNING);  break;	}

And now it works!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...