ImageMagick转换工作在命令行,但不是通过PHP exec() [英] ImageMagick convert works in commandline, but not via PHP exec()

查看:165
本文介绍了ImageMagick转换工作在命令行,但不是通过PHP exec()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP的 exec()使用ImagicMagick的 convert 转换图像。这是在CentOS服务器上运行。

  exec(convert http://www.google.com/images/srpr/ logo3w.png.jpg 
-resize 640 /home/mysite/public_html/public/img/posts/original/1414_301a4.jpg);

使用 exec()新图像出现在目标文件夹中。但是,如果我在shell中运行相同的命令,它可以正常工作!



我相信这是一个PATH问题。如果是这样,我如何检查PHP正在使用的路径,如何在PHP中设置正确的路径?

解决方案

首先,应尝试使用确实存在且可检索的输入文件:

 wget http://www.google.com/images/srpr/logo3w.png.jpg 

--2012-08-21 20:55:24-- http://www.google.com /images/srpr/logo3w.png.jpg
解析www.google.com(www.google.com)... 173.194.35.179,173.194.35.177,173.194.35.178,...
连接到www.google.com(www.google.com)| 173.194.35.179 |:80 ...已连接。
HTTP请求发送,等待响应... 404未找到
2012-08-21 20:55:24错误404:找不到。

然后查看您的PHP使用:

  exec(它转换2> /tmp/whichconvert.2 1> whichconvert.1)



  tmp / whichconvert。{1,2} 

最后, 转换:

 的完整路径exec(/ usr / local / full / path / to / convert标志:
-resize 640 /home/mysite/public_html/public/img/posts/original/1414_301a4.jpg);

,然后

 <  


更新:



您要检索的文件可能不是 logo3w.png .jpg ,但 logo3w.png

 
wget http://www.google.com/images/srpr/logo3w.png
--2012-08-21 21:04:22-- http://www.google.com/images/srpr/ logo3w.png
解析www.google.com(www.google.com)... 173.194.35.180,173.194.35.177,173.194.35.179,...
连接到www.google.com www.google.com)| 173.194.35.180 |:80 ...已连接。
HTTP请求发送,等待响应... 200 OK
长度:7007(6.8K)[image / png]
保存到:'logo3w.png'

100%[============================================== =======>] 7,007 --.- K / s in 0.02s

2012-08-21 21:04:22(451 KB / s) - 'logo3w.png'保存[7007/7007]



此外,仅适用于本地文件URIs),您可能需要检查 convert 使用的 http委托是否确实安装在您的系统上:

  convert -list delegate | grep http 
https => / opt / local / bin / curl-s -k -o%ohttps:%M

另外,检查您的PHP运行的用户帐户是否确实有权写入目标目录:

  exec(touch / home / mysite / public_html / public / img / posts / original / touchtest); 

,然后

  ls -l / home / mysite / public_html / public / img / posts / original / touchtest 


I am using PHP's exec() to convert an image using ImagicMagick's convert. This is being run on a CentOS server.

exec(convert http://www.google.com/images/srpr/logo3w.png.jpg 
    -resize 640 /home/mysite/public_html/public/img/posts/original/1414_301a4.jpg);

Using exec() does not cause the new image to appear in the destination folder. However if I were to run the same command in the shell, it works perfectly!

I believe this is a PATH problem. If so, how can I check the path that PHP is using, and how can I set the correct path in PHP?

解决方案

First, you should try with an input file that does indeed exist and is retrievable:

wget http://www.google.com/images/srpr/logo3w.png.jpg

  --2012-08-21 20:55:24--  http://www.google.com/images/srpr/logo3w.png.jpg
  Resolving www.google.com (www.google.com)... 173.194.35.179, 173.194.35.177, 173.194.35.178, ...
  Connecting to www.google.com (www.google.com)|173.194.35.179|:80... connected.
  HTTP request sent, awaiting response... 404 Not Found
  2012-08-21 20:55:24 ERROR 404: Not Found.

Then, to see which convert your PHP uses:

exec(which convert 2>/tmp/whichconvert.2 1>whichconvert.1)

and

cat /tmp/whichconvert.{1,2}

Last, also try with the full path to convert:

exec(/usr/local/full/path/to/convert logo: 
-resize 640 /home/mysite/public_html/public/img/posts/original/1414_301a4.jpg);

and then

identify /home/mysite/public_html/public/img/posts/original/1414_301a4.jpg


Update:

The file that you meant to retrieve was probably not logo3w.png.jpg, but logo3w.png:

  wget http://www.google.com/images/srpr/logo3w.png
  --2012-08-21 21:04:22--  http://www.google.com/images/srpr/logo3w.png
  Resolving www.google.com (www.google.com)... 173.194.35.180, 173.194.35.177, 173.194.35.179, ...
  Connecting to www.google.com (www.google.com)|173.194.35.180|:80... connected.
  HTTP request sent, awaiting response... 200 OK
  Length: 7007 (6.8K) [image/png]
  Saving to: ‘logo3w.png’

  100%[=====================================================>] 7,007       --.-K/s   in 0.02s   

  2012-08-21 21:04:22 (451 KB/s) - ‘logo3w.png’ saved [7007/7007]

Also, in case it works for local files only (not remote http-URIs) you may need to check if the http delegate used by convert is indeed installed on your system:

convert -list delegate | grep http
      https =>          "/opt/local/bin/curl" -s -k -o "%o" "https:%M"

Plus, check if the user account your PHP runs under does indeed have the right to write to the target directory:

exec(touch /home/mysite/public_html/public/img/posts/original/touchtest);

and then

ls -l  /home/mysite/public_html/public/img/posts/original/touchtest

这篇关于ImageMagick转换工作在命令行,但不是通过PHP exec()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆