...

View Full Version : i want to output an image as jpg file not bitmap file



kamkam
08-25-2009, 06:40 AM
Hi;

I am trying to output an image to jpg file, but my code in the following output to bitmap file, Could anyone tell me why, please.



<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header('Content-type:image/jpeg');
header('Content-type:image/gif');
header('Content-type:image/pjpeg');
header('Content-type:image/pipeg');
header('Content-type:image/png');
header('Content-type:image/x-png');

function resizeImage($originalImage,$toWidth,$toHeight, $maintain=true){
//check that image exists
if (!is_file($originalImage) || !is_readable($originalImage)) return false;
// Get the original geometry and calculate scales
list($width, $height) = getimagesize($originalImage);
if ($maintain) list($newWidth, $newHeight) = ( (($toWidth/$toHeight) > ($width/$height)) ?array (intval(($toWidth * $width/$height)), intval($toHeight)) : array (intval($toWidth), intval(($toHeight * $height/$width))));

// Resize the original image
$imageResized = imagecreatetruecolor($newWidth, $newHeight);
$imageTmp = imagecreatefromjpeg ($originalImage);
imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
return $imageResized;
}

$image=resizeImage("./upload/cat.jpg",200,200,"true"); //this one shows on the browser
imagejpeg($image, null, 20);



?>

kamkam
08-25-2009, 09:26 AM
Thanks, i have solved out the problem already.

i just keep the

header('Content-type:image/jpeg');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum