开发者

ImageMagick compare not returning anything to php shell_exec()

I want to compare two images using Image Magick. For this I am using following command in windows command prompt

compare -verbose -metric mae image1.jpg image2.jpg difference.png

This command compares image1 and image2 and prints the resultant output to command prompt window and generates a difference.jpg file that shows difference between two images.

But when I run same command using php shell_exec() no output is returned. I know that the command is being executed by php as difference.jpg is being generated but no output is returned by the function. Similarly when i try passth开发者_Go百科rough() or system() to get output, again the command is being executed but no output is returned.But when I use builtin system commands like dir I can easily get output.

Any help will be appreciated as I am stuck on this for hours but still no success

Thanks


I solved the problem. Its strange that imagemagick compare with verbose arguement does not send anything to normal command promt output. It sends output to stderr. Stderr normally receives error output. But here this command is writing normal output to stderr.

As output is going to stderr so shell_exec() is unable to get it. In order to capture it in shell_exec() we will have to append 2>&1 to command. This will redirect stderr to normal command prompt output.


The ImageMagick compare command normally doesn't produce any output. You give it two input files and the name of the output file, and it quietly creates the output file.

If there's an error, it will write an error message to stderr and set a non-zero exit status. (There should be a way to get the exit status, but I don't know PHP.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜