To execute its functionality do:
< img src="img_resize.php?path=logo.jpg&imgWidth=100" >
and it will work.
Note: File formats supported are jpg, jpeg, png, gif and wbmp. For transparent images it showes black background.
Code is given bellow. Code file is attached also.
resizeimage( $_GET['path'], $_GET['imgWidth']);
function resizeimage($overlay, $autosize){
//Find if overlay image exists
if(!file_exists($overlay)) {
die("Overlay image does not exist.");
}
$extension_o = strtolower(substr($overlay, strrpos($overlay, ".") + 1));
//Load overlay image from file
switch ($extension_o)
{
case 'jpg':
$overlay = imagecreatefromjpeg( $overlay);
break;
case 'jpeg':
$overlay = imagecreatefromjpeg( $overlay);
break;
case 'png':
$overlay = imagecreatefrompng( $overlay);
break;
case 'gif':
$overlay = imagecreatefromgif( $overlay);
break;
case 'wbmp':
$overlay = imagecreatefromwbmp( $overlay);
break;
default:
die("Image is of unsupported type.");
}
// Get the size of overlay
$oowidth = imagesx($overlay);
$ooheight = imagesy($overlay);
$owidth = $autosize;
$oheight = $autosize;
$oheight = $ooheight * ($owidth/$oowidth);
$owidth = $oowidth * ($oheight/$ooheight);
$image_resized_o = imagecreatetruecolor($owidth, $oheight);
imagecopyresampled($image_resized_o, $overlay, 0, 0, 0, 0, $owidth, $oheight, $oowidth, $ooheight);
// make white color tarnsaparent for Overlay image
$img = imagecreatetruecolor($owidth,$oheight);
// from this one can make transparent given color RGB now it make white color //transparent
$trans = imagecolorallocate($img,255,255,255);
imagecolortransparent($img,$trans);
imagecopy($img,$image_resized_o,0,0,0,0,$owidth,$oheight);
imagetruecolortopalette($img, true, 256);
imageinterlace($img);
//=========================================================
header("Content-type: image/jpeg");
header("Content-Disposition: filename=" . $overlay);
imagejpeg($img); // to view image in web browser
}
?>
Palladium Engagement Rings
11 years ago
0 comments:
Post a Comment