简体   繁体   English

php shell_exec不能与imagemagick命令一起使用

[英]php shell_exec doesn't work with imagemagick commands

I try to convert a rgb color to transparent 我尝试将rgb颜色转换为透明颜色

When i use this code in the command line, it works perfect. 当我在命令行中使用此代码时,它完美无缺。

convert -transparent 'RGB(249,249,255)' /home/me/web/my.png /home/me/web/mynew.png

But when i use it with php: 但是当我使用它与PHP:

<?php

error_reporting(E_ALL);
ini_set('display_errors', '1');

$output = shell_exec("convert -transparent 'RGB(249,249,255)' /home/me/web/my.png /home/me/web/mynew.png");

?>

i get the error: 我收到错误:

convert: unable to open image `/home/me/web/mynew.png': @ error/blob.c/OpenBlob/2498. 转换:无法打开图像`/home/me/web/mynew.png':@ error / blob.c / OpenBlob / 2498。

Has anyone a idea? 有人有想法吗?

you have to use relative paths to your homedir (because of shell_exec) otherwise you have to use absolute paths. 你必须使用homedir的相对路径(因为shell_exec),否则你必须使用绝对路径。

But why dont you use imagemagick for php ? 但为什么你不使用imagemagick的PHP

To me that looks like an access-rights issue. 对我来说,这看起来像一个访问权限问题。 Your web server tries to write a file inside your home directory. 您的Web服务器尝试在主目录中写入文件。

Normally your home-directory is protected in such a way that no one except yourself can write files in there. 通常,您的主目录受到保护,除了您自己以外没有人可以在那里写文件。 Therefore your web server can not create the new file while you can when using the terminal. 因此,在使用终端时,您的Web服务器无法创建新文件。

Check the access rights to the folder that shall contain the new image and allow the user that is running the web server to write to that folder. 检查包含新映像的文件夹的访问权限,并允许运行Web服务器的用户写入该文件夹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM