gpt4 book ai didi

ImageMagick 使用 PHP 执行路径进行转换

转载 作者:行者123 更新时间:2023-12-03 09:24:12 26 4
gpt4 key购买 nike

我已在本地 Windows 7 PC 上成功安装 ImageMagick。并测试转换 C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg

但是当我尝试从名为 C:\xampp\htdocs\test\index.php 的 PHP 文件执行此操作时与代码

<?php
exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg", $output, $return);
?>

它不起作用。 a.jpg 文件存在。我正在使用浏览器运行路径为 http://localhost/test/index.php

的 index.php 文件

$output 为空,$return 为 1。

但是当我使用时

<?php
exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert", $output, $return);
?>

我得到的输出为 Imagemagick 版本...如果我在命令提示符中运行命令“convert”,则会得到相同的输出。我在 Windows 7 中使用 xamp。我搜索了很多,但其中提到的问题不是我遇到的。

因为当我在 PHP exec 中仅使用“convert”时,我得到了输出。

所以无法理解实际问题是什么。

最佳答案

我已经为这个问题绞尽脑汁好几个小时了。

exec("C:\Program Files\ImageMagick-6.8.9-Q16\convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg", $output, $return);

这段代码应该可以正常工作,只有一个问题,尝试运行“C:\Program Files\ImageMagick-6.8.9-Q16\convert C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg"不带引号 在命令提示符中,您将无法识别“C:\Program”。需要引用转换exe的路径。

试试这个 exec('"C:\Program Files\ImageMagick-6.8.9-Q16\convert"C:\xampp\htdocs\test\images\a.jpg C:\xampp\htdocs\test\images\b.jpg', $output, $return);

应该可以。

干杯!

关于ImageMagick 使用 PHP 执行路径进行转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24951905/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com