douhuang3833 2009-06-06 07:44
浏览 30

我怎样才能避免php中的getimage()警告消息

Recently i worked in project. there i need to a resize a picture and i use the following class.

class SimpleImage 
{  
   var $image;
   var $image_type; 
   function load($filename) 
   {      
      $image_info = getimagesize($filename);
      $this->image_type = $image_info[2];
      if($this->image_type == IMAGETYPE_JPEG) 
      {
         $this->image = imagecreatefromjpeg($filename);
      } 
      elseif( $this->image_type == IMAGETYPE_GIF ) 
      {
         $this->image = imagecreatefromgif($filename);
      } 
      elseif( $this->image_type == IMAGETYPE_PNG ) 
      {
         $this->image = imagecreatefrompng($filename);
      }
   }
   function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) 
   {
      if( $image_type == IMAGETYPE_JPEG ) 
      {
         imagejpeg($this->image,$filename,$compression);
      } elseif( $image_type == IMAGETYPE_GIF ) 
      {
         imagegif($this->image,$filename);         
      } elseif( $image_type == IMAGETYPE_PNG ) 
      {
         imagepng($this->image,$filename);
      }   
      if( $permissions != null) 
      {
         chmod($filename,$permissions);
      }
   }
   function output($image_type=IMAGETYPE_JPEG) 
   {
      if( $image_type == IMAGETYPE_JPEG ) 
      {
         imagejpeg($this->image);
      } 
      elseif( $image_type == IMAGETYPE_GIF ) 
      {
         imagegif($this->image);         
      } 
      elseif( $image_type == IMAGETYPE_PNG ) 
      {
         imagepng($this->image);
      }   
   }
   function getWidth() 
   {
      return imagesx($this->image);
   }
   function getHeight() 
   {      
      return imagesy($this->image);
   }
   function resizeToHeight($height) 
   {
      $ratio = $height / $this->getHeight();
      $width = $this->getWidth() * $ratio;
      $this->resize($width,$height);
   }
   function resizeToWidth($width) 
   {
      $ratio = $width / $this->getWidth();
      $height = $this->getheight() * $ratio;
      $this->resize($width,$height);
   }
   function scale($scale) 
   {
      $width = $this->getWidth() * $scale/100;
      $height = $this->getheight() * $scale/100; 
      $this->resize($width,$height);
   }
   function resize($width,$height) 
   {      
      $new_image = imagecreatetruecolor($width, $height);      
      imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
      $this->image = $new_image;   
   }      
}

when i use the class it show a warning message like bellow

Warning: getimagesize(seeker/SeekerPhoto/so.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\xampp\htdocs\job\insphoto.php on line 11

Warning: images): supplied argument is not a valid Image resource in C:\xampp\htdocs\job\insphoto.php on line 60

Warning: imagesy(): supplied argument is not a valid Image resource in C:\xampp\htdocs\job\insphoto.php on line 64

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in C:\xampp\htdocs\job\insphoto.php on line 87

How can i avoid this kind of warning message. Thank you Arif..

  • 写回答

2条回答 默认 最新

  • dousi4950 2009-06-06 08:19
    关注

    You should check first if the file exists (is_file function) and is readable (is_readable function).

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog