这个 php GD 代码有问题吗?
if ($img = @imagecreatefromjpeg('./images/upload/13/1.JPG')) {
imagejpeg($img, $path, 100);
imagedestroy($img);
} else {
die ("image was not created or saved");
}
我收到消息:
警告: imagejpeg(): 8 不是 C:\xampp\htdocs\invivid\libraries\photograph_classes.php 中的有效图像资源,第 276 行
警告:imagedestroy(): 8 不是有效图像资源位于 C:\xampp\htdocs\invivid\libraries\photograph_classes.php 第 277
行 图像最初是被创建的,我们从 if 语句中知道这一点,但为什么 imagejpeg 或 imagedestroy 不能正常工作?
解决方案:好的,我认为这与不正确的 $path 变量有关,它现在似乎工作正常。
if ($img = @imagecreatefromjpeg('./images/upload/13/1.JPG')) {
imagejpeg($img, $path, 100);
imagedestroy($img);
} else {
die ("image was not created or saved");
}
I'm getting the message:
Warning: imagejpeg(): 8 is not a valid Image resource in C:\xampp\htdocs\invivid\libraries\photograph_classes.php on line 276
Warning: imagedestroy(): 8 is not a valid Image resource in C:\xampp\htdocs\invivid\libraries\photograph_classes.php on line 277
The image is being created initially, we know this from the if statement, but why doesn't imagejpeg or imagedestroy work properly?
Solution: Ok, I think it had something to do with an incorrect $path variable, it seems to be working fine now.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 imagecreatefromjpeg 上的文档页面(尽管这看起来特别难以置信):
另一件值得尝试的事情是进行设置
,看看是否可以解决图像损坏的假定问题。
From the documentation page on imagecreatefromjpeg (although this seems particulary implausible):
Another worthwhile thing to try could be setting
and see if that solves presumed issues with corrupted images.
我从来没有像这样使用过它(没有创建新图像,进行一些操作等),但手册似乎有点模糊: imagecreatefromjpeg 返回图像资源标识符和imagejpeg 需要一个图像资源,由图像创建函数之一返回。看起来确实是一样的,但也许并非如此。
I´ve never used it like that (without creating a new image, doing some manipulation, etc.), but it seems the manual is a bit vague: imagecreatefromjpeg returns an image resource identifier and imagejpeg needs an image resource, returned by one of the image creation functions. It certainly looks the same, but perhaps they are not.