php - 谁能帮我解决这个错误?
问题描述
我的代码:
<!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
解决方案
您的呼叫imagerotate
失败并返回false
- 请参阅文档。
这就是为什么imagejpeg
抱怨它。
您可以将其更改为
$imgRotated = imagerotate($img, 45, 0);
这应该会更好。
推荐阅读
- swift - 如何在 Swift 中将字节解码为字符串?
- c# - 如何加快图片在picturebox.image 和其他元素上的渲染速度?
- windows - 如何在 Windows 11 中检查屏幕开启时间?
- docker - 如何将 docker run --cap-add SYS_BOOT --cap-add SYS_ADMIN 添加到 Dockerfile 本身?
- java - 为什么运行单个测试时会出现JUnit平台错误?
- python - 用于 pip / 诗歌的 Python 特殊版本
- reactjs - 在 NextJS 中查询 MongoDB 时如何“确保 CORS 响应标头值有效”
- google-cloud-platform - 实例停止或关闭时的 GCP 警报
- google-sheets - 如何使用另一个工作表有条件地更改 Google 工作表的值
- ios - 如何修复有关使用 CocoaPods 构建 Firebase 的警告?