2011-04-04 112 views
1

我想调整上传的图像。我得到错误PHP图像调整大小错误

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: gd-jpeg, libjpeg: recoverable error: Premature end of JPEG file in /home/rumdood/lib/photograph.php on line 309

Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/home/rumdood/public_html/uploads/13018946005603.jpg' is not a valid JPEG file in /home/rumdood/lib/photograph.php on line 309

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/rumdood/lib/photograph.php on line 410

Warning: Cannot modify header information - headers already sent by (output started at /home/rumdood/lib/photograph.php:309) in /home/rumdood/application.php on line 22

而图像没有被调整大小。最后一个错误是由于标题功能。

管道309是这样

$this->image['render'] = imagecreatefromjpeg($this->s_image); 

线410是这样

imagecopyresampled($this->image['composite'], $this->image['render'], 
        0, 0, 0, 0, $new_width, $new_height, 
        $this->image['width'], $this->image['height']); 

我的PHP版本是PHP Version 5.2.6

我来自的phpinfo

GD Support   enabled 
GD Version   bundled (2.0.34 compatible) 
FreeType Support enabled 
FreeType Linkage with freetype 
FreeType Version 2.1.9 
GIF Read Support enabled 
GIF Create Support enabled 
JPG Support   enabled 
PNG Support   enabled 
WBMP Support  enabled 
XPM Support   enabled 
XBM Support   enabled 
+0

什么是$ this-> s_image? – grc 2011-04-04 06:30:58

+0

沿线的某处$ this-> s_image未获取数据填充,已损坏或不是jpg – 2011-04-04 06:32:28

+0

@grc多数民众赞成的图像的绝对文件路径 – 2011-04-04 06:35:22

回答

4

由于@charles建议..这两个错误是自explanitory

检查有效图像从

if($_FILES["userPicture"]["error"] == 0) { 
// File was uploaded ok, so it's ok to proceed with the filetype check. 
$uploaded_type = exif_imagetype($_FILES["userPicture"]["tmp_name"]); 
// What we have now is a number representing our file type. 

switch($uploaded_type) { 
    case "1": 
     $uploaded_type = "gif"; 
    break; 
    case "2": 
     $uploaded_type = "jpg"; 
    break; 
    case "3": 
     $uploaded_type = "png"; 
    break; 
} 

}


对于 imagecreatefromjpeg():GD-JPEG,libjpeg的:可恢复的错误:JPEG的提前结束

这是一个与php 5和gd2的问题。继承人如何解决它

  • PHP 4:neccesarry它无需任何操作应该工作正常
  • PHP 5.0 - 5.1.2 =升级到最新的PHP 5
  • PHP 5.1.3 - 电流=声明此变量在你的文件中打电话之前imagecreatefromjpeg()
  • ini_set('gd。jpeg_ignore_warning',1);

不能在页面的顶部修改标题信息ob_start();

参考

3

GD错误ORS,

libjpeg: recoverable error: Premature end of JPEG file

...is not a valid JPEG file

是不言自明。您正在尝试使用的图像没有被底层的JPEG解析器识别为有效。该文件很可能已损坏或被截断。

这是图像本身的问题,而不是您的代码。你的代码看起来很好。

2

看起来像你想加载的图像不是真正的JPG(可能有人刚刚重命名或某事)。尝试使用一些图像处理程序(如GIMP)重新保存它。或者,如果您已将其上传到服务器,则可能是上传时出现了一些错误。另外,如果文件权重超过一个文件大小限制在服务器上,它可能会残酷地切割。

Warning: Cannot modify header information - headers already sent by (output started at /home/rumdood/lib/photograph.php:309) in /home/rumdood/application.php on line 22 

您必须在代码开始时发送标题。 <?php标签之前不能有空格。

+1

我期待“头已发送”的错误是抱怨事实错误消息被发射并且输出缓冲未被使用。 – Charles 2011-04-04 06:31:14