繁体   English   中英

GD图像调整大小和标题(内容类型)

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM