这个 php GD 代码有问题吗?

发布于 2024-09-02 01:44:24 字数 580 浏览 4 评论 0原文

     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 技术交流群。

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

发布评论

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

评论(2

狠疯拽 2024-09-09 01:44:28

来自 imagecreatefromjpeg 上的文档页面(尽管这看起来特别难以置信):

imagecreatefromJPEG is for .JPEG and .JPG ending
&
imagecreatefromjpeg is for .jpeg and .jpg ending.

That function is case sensitive.

另一件值得尝试的事情是进行设置

ini_set('gd.jpeg_ignore_warning', 1);

,看看是否可以解决图像损坏的假定问题。

From the documentation page on imagecreatefromjpeg (although this seems particulary implausible):

imagecreatefromJPEG is for .JPEG and .JPG ending
&
imagecreatefromjpeg is for .jpeg and .jpg ending.

That function is case sensitive.

Another worthwhile thing to try could be setting

ini_set('gd.jpeg_ignore_warning', 1);

and see if that solves presumed issues with corrupted images.

究竟谁懂我的在乎 2024-09-09 01:44:27

我从来没有像这样使用过它(没有创建新图像,进行一些操作等),但手册似乎有点模糊: 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.

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