php - 与 PHP 一起使用时,Imagemagick 转换命令返回错误代码 4
问题描述
我正在使用 PHPexec
函数执行 ImageMagick 命令,它返回一个error code 4
意思probably
是The system cannot open the file
当我在 Windows 终端中运行相同的命令时它工作正常。我正在使用以下命令来调整图像大小:
在终端(工作正常)
convert -resize 150^% ad.png res_ad.png
在 PHP 中(返回错误代码 4)
exec(escapeshellcmd("convert -resize 150% $file_name.png res_$file_name.png"), $output2, $return2)
PS:我已经检查并且图像的路径是正确的。
解决方案
我只使用 php 从 Imagemagick 返回了 1 或 0,所以我不知道 4 是从哪里来的。
我使用了与您类似的代码,但从未在 exec 中使用过 escapeshellcmd。exec 正在调用外部程序,我不确定您是否可以在那里使用它。
尝试(注意在大多数情况下输入图像在转换之后):
exec("convert $file_name.png -resize 150% res_$file_name.png");
您可以在将输入和输出图像文件名发送到 exec() 之前对其进行验证
不同的错误报告:
$array=array();
echo "<pre>";
exec("convert $file_name.png -resize 150% res_$file_name.png 2>&1", $array);
echo "<br>".print_r($array)."<br>";
echo "</pre>";
推荐阅读
- python - 如何通过 csv 获取加载到 BigQuery 中的行数
- python - 大文件通过python上传到视频索引器
- .htaccess - 301 将整个域重定向到新的一个 + 几个单独的页面到新的 url
- python - 如何将您安装的变压器保存到 blob 中,以便您的预测管道可以在 AML 服务中使用它?
- php - Auth::user()->id 返回“试图获取非对象的属性”——Laravel 5.8
- c# - 在更改字段类型时命名枚举
- mysql - 如何在将 SUM() 用于另一个日期的子句中按日期使用 MIN()?
- c# - 通过 FatSecret Api 2.0 c# 获取响应
- javascript - 无法访问 webform ascx 文件中的模型
- scala - 在成功结果数之后,在列表上结束 Scala 中的过滤器