[英]GD Image resize and Header(Content-type)
我試圖找出Header(content-type:image / png)的正確用法。我有一個上傳腳本,可以正確地上傳和調整大小,無論是否包含標題,但似乎建議使用標題。問題是帶有標頭的腳本一旦完成,就會在窗口的左上角拋出“破碎的img”圖標並退出腳本。 如果要重定向到新頁面,如何使它的行為有所不同。 在腳本末尾添加Header(location:...)似乎沒有什么不同。 任何幫助表示贊賞。
<?PHP
/*image resize with Imagick*/
function imageResize($image){
/*call to imagick class and resize functions will go here*/
echo 'the image to be resized is : '.$image;
$newImage=new Imagick();
$newImage->readImage($image);
$newImage->resizeImage(1024,768,imagick::FILTER_LANCZOS, 1);
$newImage->writeImage('myImage.png');
$newImage->clear();
$newImage->destroy();
}
/*image resize with GD image functions*/
function imgResize($image){
header('Content-Type: image/png');
$newWidth='1024';
$newHeight='768';
$size=getimagesize($image);
$width=$size[0];
$height=$size[1];
//return $width;
$dest=imagecreatetruecolor($newWidth,$newHeight);
$source=imagecreatefrompng($image);
imagecopyresized($dest,$source,0,0,0,0,$newWidth,$newHeight,$width,$height );
return imagepng($dest,'./users/uploads/newimage.png');
imagedestroy($dest);
}
/*Function that actually does the upload*/
function file_upload(){
if(!empty( $_FILES) ){
print_r($_FILES);
echo '<hr>';
$tmpFldr=$_FILES['upFile']['tmp_name'];
$fileDest='./users/uploads/'.$_FILES['upFile']['name'];
if(move_uploaded_file($tmpFldr,$fileDest)){
echo 'Congratulations, your folder was uploaded successfully <br><br>';
}
else{
echo 'Your file failed to upload<br><br>';
}
return $fileDest;
} else{die( 'Nothing to upload');}
} /*End file upload function */
$fileLocation=file_upload();
echo 'location of the new file is : '.$fileLocation.'<hr>';
$newImage=imgResize($fileLocation);
?>
您不能同時提供圖片和重定向。 如果要輸出PNG圖像,則輸出Content-Type標頭,但不包括Location標頭。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.