php图像调整大小错误
我正在尝试调整上传的图像的大小。我收到错误
警告: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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如@charles建议的那样..这两个错误都是不言自明的
检查来自
}
For 的 有效图像
imagecreatefromjpeg()
:gd-jpeg、libjpeg:可恢复错误:JPEG 提前结束这是 php 5 和 gd2 的问题。下面是如何修复它
imagecreatefromjpeg()< 之前在文件中声明此变量/code>
对于无法修改头信息,在页面顶部写入
ob_start();
参考
As @charles suggested.. both error are self explanitory
check for valid image from
}
For
imagecreatefromjpeg()
: gd-jpeg, libjpeg: recoverable error: Premature end of JPEGit was a problem with php 5 and gd2. Heres how to fix it
imagecreatefromjpeg()
for Cannot modify header information write
ob_start();
at the top of pageReference
错误,
和
这一点是不言自明的。您尝试使用的图像未被底层 JPEG 解析器识别为有效。该文件很可能已损坏或被截断。
这是图像本身的问题,而不是您的代码的问题。你的代码看起来不错。
The errors,
and
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.
看起来您尝试加载的图像不是真正的 JPG(可能有人刚刚重命名或其他什么)。尝试使用一些图像处理程序(如 GIMP)重新保存它。或者如果您已将其上传到服务器,则可能上传过程中出现了一些错误。此外,如果文件重量超过服务器上的文件大小限制,则可能会被残酷地削减。
您必须在代码开头发送标头。
标记之前甚至不能有空格。
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.
You have to send header at beggining of the code. there can't be even a space before
<?php
tag.