谁能帮我解决这个错误?

时间:2020-05-03 12:31:37

标签: php runtime-error imagecreatefromjpg

我的代码:

      <!DOCTYPE html>
        <html>
        <body>

        <h1>Rotating an Image</h1>

        <?php

        $img = imagecreatefromjpeg("myPic.jpg");
        $imgRotated = imagerotate($img, 45, -1);
        imagejpeg($imgRotated, "myPic.jpg", 100);
        ?>
        <img src="myPic.jpg"/><img src="myPicRotated.jpg">

        </body>
        </html>

错误

Warning: imagejpeg() expects parameter 1 to be resource, bool given in C:\xampp\htdocs\MyWebsite\index.php on line 11

1 个答案:

答案 0 :(得分:1)

您对imagerotate的调用失败,并返回false-请参阅文档。

这就是imagejpeg对此抱怨的原因。

您可以将其更改为

$imgRotated = imagerotate($img, 45, 0);

应该会更好。