已解决:安装 Homebrew ImageMagick 后,MAMP Php 无法执行(“转换”)

发布于 2024-12-01 01:01:53 字数 1296 浏览 3 评论 0原文

我在 Lion 上使用 Homebrew 安装了 Imagemagick,一切都很好,只是从 php 调用时它根本不起作用。控制台:

$ convert -version
Version: ImageMagick 6.7.1-1 2011-07-29 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP   

$ which convert
/usr/local/bin/convert

PHP:

echo exec ('convert -version');

或 exec('转换-版本', $output); var_dump($输出);

不产生任何内容(或产生空数组)。

exec ('/usr/local/bin/convert') // works, but
exec ('which convert') // doesn't

我需要在本地进行测试,以确保我可以在生产环境中检测到转换。但我无法正确测试它。 PATH 已设置并且可以在终端中使用,但不能在 PHP 中使用。

已解决:

事实证明,要使 php 正常工作,convert 应该位于 /usr/bin/ 中,所以这解决了它:

ln -s /usr/local/bin/convert /usr/bin/convert

更新

这是因为MAMP,这里是修复:http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp

打开 /Applications/MAMP/Library/bin/envvars

并注释掉以下几行:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

完成。

I installed Imagemagick using Homebrew on Lion, everything is fine except that it doesn't work at all when being called from php. Console:

$ convert -version
Version: ImageMagick 6.7.1-1 2011-07-29 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2011 ImageMagick Studio LLC
Features: OpenMP   

$ which convert
/usr/local/bin/convert

PHP:

echo exec ('convert -version');

or
exec('convert -version', $output);
var_dump($output);

Produces nothing (or an empty array).

exec ('/usr/local/bin/convert') // works, but
exec ('which convert') // doesn't

I need to test this locally to make sure I can detect convert in production environment. But I can't properly test it. The PATH is set and it works in Terminal, but not from PHP.

Resolved:

Turns out, for php to work convert should be in /usr/bin/ so this solved it:

ln -s /usr/local/bin/convert /usr/bin/convert

Update

It was becasue of MAMP, here is the fix: http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp

Open /Applications/MAMP/Library/bin/envvars

And comment out the following lines:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

Done.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(6

悲欢浪云 2024-12-08 01:01:53

在这里添加我自己的答案,以便您可以投票:

这是由 MAMP 引起的,这是修复方法: http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp

打开/Applications/MAMP/Library/bin/envvars

并注释掉以下行:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

完成。

Adding my own answer here so you can vote:

It was caused by MAMP, here is the fix: http://firedevcom.tumblr.com/post/22791937644/fix-for-homebrew-imagemagick-and-mamp

Open /Applications/MAMP/Library/bin/envvars

And comment out the following lines:

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

Done.

不…忘初心 2024-12-08 01:01:53
sudo ln -s /usr/local/bin/convert /usr/bin/convert
sudo ln -s /usr/local/bin/convert /usr/bin/convert
烟火散人牵绊 2024-12-08 01:01:53

验证convert in 是服务器的PATH 环境变量。或者只指定完整路径:

exec('/usr/local/bin/convert -version');

Verify that convert in is the server's PATH environment variable. Or just specify the full path:

exec('/usr/local/bin/convert -version');
随波逐流 2024-12-08 01:01:53

exec 返回命令结果的最后一行,该行恰好是一个空字符串。
如果你想获得输出,只需执行以下操作:

exec('convert -version', $output);
var_dump($output); // it is an array which filled with every line of output from the command

The exec returns the last line from the result of the command which happens to be an empty string.
If you want to get the output, just do something like this:

exec('convert -version', $output);
var_dump($output); // it is an array which filled with every line of output from the command
爱本泡沫多脆弱 2024-12-08 01:01:53

只需使用 exec("PATH=\$PATH:/usr/local/bin; Convert file.pdf file.png"); 它会在运行时将 Convert 添加到 PATH 。

Simply use exec("PATH=\$PATH:/usr/local/bin; convert file.pdf file.png"); It will add convert to PATH on runtime.

听你说爱我 2024-12-08 01:01:53

而不仅仅是 exec("convert .... ");
使用完整路径。你可以通过在终端输入来获取它

类型转换

你应该得到类似的东西:
转换是散列的(/opt/local/bin/convert),

所以现在使用:

exec(“/opt/local/bin/convert ....”);

[致谢 @Nikki]

在评论之后

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
导出 DYLD_LIBRARY_PATH

在 /Applications/MAMP/Library/bin/envvars 中

instead of just exec("convert .... ");
use a full path. you can get it by typing the terminal

type convert

you should get something like:
convert is hashed (/opt/local/bin/convert)

so now use:

exec("/opt/local/bin/convert .... ");

[credits to @Nikki]

after that comment out

DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
export DYLD_LIBRARY_PATH

in /Applications/MAMP/Library/bin/envvars

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