php图像调整大小错误

发布于 2024-10-30 19:39:22 字数 1471 浏览 1 评论 0原文

我正在尝试调整上传的图像的大小。我收到错误

警告:imagecreatefromjpeg() [function.imagecreatefromjpeg]:gd-jpeg、libjpeg:可恢复错误:/home/rumdood/lib/photograph.php 第 309 行中 JPEG 文件过早结束

警告:imagecreatefromjpeg() [function.imagecreatefromjpeg]: '/home/rumdood/public_html/uploads/13018946005603.jpg' 不是 /home/rumdood/lib/photograph.php 第 309 行中的有效 JPEG 文件

警告:imagecopyresampled():提供的参数不是 /home/rumdood/lib/photograph.php 第 410 行中的有效图像资源

警告:无法修改标头信息 - 已由 /home/rumdood/lib/photograph.php:309 中的第 22 行 /home/rumdood/application.php 中的输出(输出从 /home/rumdood/lib/photograph.php:309 开始)发送

并且图像没有被调整大小。最后一个错误是由于头函数引起的。

第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

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

I am trying to resize an uploaded image. I am getting error

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

And the image is not being resized. The last error is due to header function.

The line 309 is like this

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

Line 410 is like this

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

And my php version is PHP Version 5.2.6

My GD from 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

不气馁 2024-11-06 19:39:22

正如@charles建议的那样..这两个错误都是不言自明的

检查来自

 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;
}

}


For 的 有效图像
imagecreatefromjpeg():gd-jpeg、libjpeg:可恢复错误:JPEG 提前结束

这是 php 5 和 gd2 的问题。下面是如何修复它

  • php 4 :无需任何操作,它应该可以正常工作
  • php 5.0 – 5.1.2 = 升级到最新的 php 5
  • php 5.1.3 – current = 在调用 imagecreatefromjpeg()< 之前在文件中声明此变量/code>
  • ini_set('gd.jpeg_ignore_warning', 1);

对于无法修改头信息,在页面顶部写入ob_start();

参考

As @charles suggested.. both error are self explanitory

check for valid image from

 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;
}

}


For
imagecreatefromjpeg() : gd-jpeg, libjpeg: recoverable error: Premature end of JPEG

it was a problem with php 5 and gd2. Heres how to fix it

  • php 4 : No action neccesarry it should work fine
  • php 5.0 – 5.1.2 = Upgrade to the latest php 5
  • php 5.1.3 – current = Declare this variable in your file before calling imagecreatefromjpeg()
  • ini_set(‘gd.jpeg_ignore_warning’, 1);

for Cannot modify header information write ob_start(); at the top of page

Reference

念﹏祤嫣 2024-11-06 19:39:22

错误,

libjpeg:可恢复错误:JPEG 文件过早结束

...不是有效的 JPEG 文件

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

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

The errors,

libjpeg: recoverable error: Premature end of JPEG file

and

...is not a valid JPEG file

are pretty self-explanatory. The image you are trying to work with is not being recognized by the underlying JPEG parser as valid. It is very likely that the file is corrupt or truncated.

This is a problem with the image itself, not your code. Your code looks fine.

疯到世界奔溃 2024-11-06 19:39:22

看起来您尝试加载的图像不是真正的 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

您必须在代码开头发送标头。 标记之前甚至不能有空格。

Looks like image you are trying to load is not true JPG (probably someone have just renamed or something). Try to resave it with some image manipulation program (like GIMP). Or if you have uploaded it to the server, probably there was some error in uploading. Also if file weight more than one file size limit on server it could be brutally cutted.

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

You have to send header at beggining of the code. there can't be even a space before <?php tag.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文