drkenap147751 2012-08-21 08:16
浏览 96
已采纳

imagemagick convert命令在php脚本中无法正常工作,但可以从命令行工作

A system call to convert in php worked for years but quit working early this year. All commands that I am using work correctly if issued from the command line using Putty.

A test php file I created to debug this is

<?  
$string = "convert  -verbose -resize 200x200  \"startline/main_menu.png\" \"image/temp222_main_menu.png\" ";
passthru($string);
?>

<IMG SRC='image/temp222_main_menu.png '  alt='main_menu'>

The output file is not created. I get this response

startline/main_menu.png PNG 600x1024 600x1024+0+0 8-bit DirectClass 92.1KB 0.020u 0:00.020

If I replace my string with this

$string = "convert  -version -resize 200x200  \"startline/main_menu.png\" \"image/temp222_main_menu.png\" ";

The output file is created but not resized.

I get this response:

Version: ImageMagick 6.6.0-4 2012-04-26 Q16 http://www.imagemagick.org Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC Features: OpenMP

The interesting thing is that this worked from 2008 until early this year. That may have been when I switched to PHP5 and a new server, not sure. This is running at 1and1.com

Tech support at 1and1 said the problem was the outfile didn't exist and closed the case. That was not very helpful.

I am wondering if there is something I need to put in my php.ini file or something.


I also tried this: exec("/usr/bin/convert -resize 200x200 image/temp222_main_menu.png"); ?>

Just a note. I put the verbose in so that I could be sure that I was in fact running the program, that there was some output returned. It also shows that it is loading the correct file. That is also why I used passthru instead of exec or system. This is just a test script. The script I was using before it broke did not use passthru but had too much going on to post. The key is that the string that is executed does not work in php but does work on the command line so it is correct.

  • 写回答

2条回答 默认 最新

  • doubaisui2526 2012-08-24 16:13
    关注

    I just went through this exact same problem. The really odd thing I noticed is that if the image happened to be the exact size I was trying to resize to, then it worked. Anywawy, It seems to be an issue with memory usage and can be fixed by a config setting in PHP. After browsing other forums I found this and it fixed it.

    Place this line at the top of your PHP script that calls imagemagick:

    putenv("MAGICK_THREAD_LIMIT=1");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部