2013-04-21 67 views
1

我想重新大小的照片在PHP中的,而循环,但我不断收到类似的错误:错误试图重新大小的图像时

Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in C:\Users\Bob\xampp\htdocs\house\allphotos.php on line 17 

Warning: imagecreatefromjpeg(): 'userphotos/27_1366493160164_BMW.jpg' is not a valid JPEG file in C:\Users\Bob\xampp\htdocs\house\allphotos.php on line 17 

Warning: imagecopyresized() expects parameter 2 to be resource, boolean given in C:\Users\Bob\xampp\htdocs\house\allphotos.php on line 27 

然后一吨的随机字符...

在下面,我试图回显出2张照片用新的尺寸选择。 我认为这与$image有关,我没有使用该功能吗?

ini_set("gd.jpeg_ignore_warning", 1); //just added 
if ($getphotos->execute()){ 
     while ($array = $getphotos->fetch(PDO::FETCH_ASSOC)){ 

      $image = imagecreatefromjpeg('userphotos/'.$array['photoname'].''); 


      list($image_width, $image_height, $type, $attr) = getimagesize('userphotos/'.$array['photoname'].''); 

      $new_size = ($image_width + $image_height)/($image_width*($image_height/100)); 
      $new_width = $image_width * $new_size; 
      $new_height = $image_height * $new_size; 

      $new_image = imagecreatetruecolor($new_width, $new_height); 
      imagecopyresized($new_image, $image, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height); 
      $imagearray = imagejpeg($new_image, null); 

      echo $imagearray; 
      //echo '<img src="userphotos/'.$array['photoname'].'">'; 

     } 
    } else { die('Query Error'); } 

回答

2

GD可以是有点过,虽然在理论上,当你打开它等等,你可以禁止警告并让它继续其快乐的方式有以下文件工作正常JPEG文件是无情的:

ini_set("gd.jpeg_ignore_warning", 1); 

这将让处理继续,并忽略警告。您的图片将更有可能仍然得到处理,没有问题。

+0

好的感谢您的解决方案,我刚刚添加它,你可以看到我的编辑,但它仍然无法正常工作。我几乎肯定错误来自'$ image = imagecreatefromjpeg ...'行。是否有某种类型的替代品可以用来使其发挥作用? – user2127833 2013-04-21 03:45:38

+0

唯一的其他建议是查看你的主机是否可以升级'jpglib'软件包 – duellsy 2013-04-21 03:51:14

+0

原来这与特定照片有关,我删除了照片并且工作正常。 – user2127833 2013-04-21 18:34:43