Help needed
Posted: Wed May 20, 2009 7:42 am
I am trying to display image thumbnail.Here i attach my code.But problem is there it needed <html> <body> tag to view in browser.But i can not add those tags because header is there.
And without <html> <body> tag i can notshow image in browser.
So, how camn I mix up <html> <body> tag with headers. I am new at php.
And without <html> <body> tag i can notshow image in browser.
So, how camn I mix up <html> <body> tag with headers. I am new at php.
Code: Select all
<?php
$thumb = createThumbnail("Winter.jpg","phpimages","-thumb", 120, 100, 100);
function createThumbnail($img, $imgPath, $suffix, $newWidth, $newHeight, $quality)
{
// Open the original image.
$original = imagecreatefromjpeg("$imgPath/$img") or die("Error Opening original");
list($width, $height, $type, $attr) = getimagesize("$imgPath/$img");
// Resample the image.
$tempImg = imagecreatetruecolor($newWidth, $newHeight) or die("Cant create temp image");
imagecopyresized($tempImg, $original, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height) or die("Cant resize copy");
// Save the image.
imagejpeg($tempImg, "$imgPath/def.jpg", $quality) or die("Cant save image");
$image1=imagecreatefromjpeg("$imgPath/def.jpg");
header('Content-Type: image/jpeg');
imagejpeg($image1);
imagedestroy($original);
imagedestroy($tempImg);
return true;
}
?>