PCHomepage
Programmer
In this snippet from a function I am working on, it is outputting the image data to the browser when I am trying to create a variable containing the data. Otherwise it is working as expected so what did I miss? Right now it is sending the image data to the screen and expecting headers which, of course, are not being sent.
In case it helps, here is the complete function which itself uses a few other custom functions all of which are working:
PHP:
imagecopyresampled($tmp, $src, 0, 0, 0, 0,$newWidth, $newHeight, $Imgwidth, $Imgheight);
switch ($ImgType) :
case 1 : $result = imagegif($tmp); break;
case 2 : $result = imagejpeg($tmp, null, 100); break;
case 3 : $result = imagepng($tmp, null); break;
case 6 : $result = imagejpeg($tmp, null, 100); break;
default : $result = imagejpeg($tmp, null, 100);
endswitch;
In case it helps, here is the complete function which itself uses a few other custom functions all of which are working:
PHP:
function ConvertImage($ImgFile, $ImgCategory) {
if (file_exists($ImgFile)) {
list($Imgwidth, $Imgheight, $ImgType, $attr) = getimagesize($ImgFile);
switch ($ImgType) :
case 1 : $src = imagecreatefromgif($ImgFile); break;
case 2 : $src = imagecreatefromjpeg($ImgFile); break;
case 3 : $src = imagecreatefrompng($ImgFile); break;
case 6 : $src = imagecreatefrombmp($ImgFile); break; // Custom function
default :
$images->Image->Errors->AddError("<font color=\"red\">Only JPG, GIF, BMP or PNG format images may be used.</font>");
$images_OnValidate = 0;
endswitch;
if ($src === FALSE) :
$images->Image->Errors->AddError("<font color=\"red\">Unable to create image.</font>");
$images_OnValidate = 0;
endif;
switch ($ImgCategory) :
case 1 : $MaxDim = 200; break;
case 5 : $MaxDim = 200; break;
case 6 : $MaxDim = 100; break;
default : $MaxDim = 200;
endswitch;
if($Imgheight > $MaxDim):
$newHeight = $MaxDim;
$newWidth = round( $Imgwidth * ($newHeight/$Imgheight));
else:
$newHeight = $Imgheight;
$newWidth = $Imgwidth;
endif;
$tmp = imagecreatetruecolor($newWidth, $newHeight);
if ($ImgType == 1):
$transparent = imagecolorallocatealpha($tmp, 255, 255, 255, 127);
imagefill($tmp, 0, 0, $transparent);
imagealphablending($tmp, FALSE);
imagesavealpha($tmp, TRUE);
endif;
[COLOR=red]imagecopyresampled($tmp, $src, 0, 0, 0, 0,$newWidth, $newHeight, $Imgwidth, $Imgheight);
switch ($ImgType) :
case 1 : $result = imagegif($tmp); break;
case 2 : $result = imagejpeg($tmp, null, 100); break;
case 3 : $result = imagepng($tmp, null); break;
case 6 : $result = imagejpeg($tmp, null, 100); break;
default : $result = imagejpeg($tmp, null, 100);
endswitch;[/color]
imagedestroy($tmp);
}
return $result;
}