使用php shell_exec()触发时,ImageMagick unix shell脚本不起作用

时间:2014-11-10 12:48:26

标签: php imagemagick shell-exec

我必须使用Fred的ImageMagick脚本创建一个图像转换序列,特别是fx transitions

在我的PHP代码中,我将所有图像调整为标准尺寸,然后将所有这些图片重命名为pic000001.jpg,pic000002.jpg,pic000003.jpg等等(我依旧计算$ count ),然后我做:

$frameIndex=0;
$frames=18;

//for all the pic000001.jpg, pic000002.jpg, pic000003.jpg.... do a transition 
//between them
for($seq=1;$seq<$count;$seq++){

        //here I take a picture and the next(IE pic000001 and pic000002)
        echo shell_exec("fxtransitions -e swirl -f $frames -d 20 -p 50 $path/pic".str_pad($seq, 6, '0', STR_PAD_LEFT).".jpg $path/pic".str_pad(($seq+1), 6, '0', STR_PAD_LEFT).".jpg $path/fx%06d.jpg");

        //here I rename the temporany frames called 
        //fx000000.jpg to fx000035.jpg for each transition 
        //to a common index
        for($c=0;$c<($frames*2);$c++){
            rename("fx".str_pad($c, 6, '0', STR_PAD_LEFT).".jpg" ,str_pad($frameIndex, 6, '0', STR_PAD_LEFT).".jpg");
            $frameIndex++;
            }
    }

然后,我使用FFMpeg组合所有帧并制作视频。 问题是fxtransition表示错误:

--- FILE DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---

(这是脚本肯定生成的消息),后跟这样的消息:

Warning: rename(fx000000.jpg,000000.jpg): No such file or directory in /var/www/html/TEST/APP/generateVideo.php on line 168

因为没有生成图片(它显示用于编号框架的aloghoritm是正确的,所以不要专注于那个)。

如果我打开服务器上的终端,使用ssh连接并运行该命令,它会给我同样的错误,除非我使用sudo。 如果我在php shell_exec上使用sudo,它将不会执行。 shell_exec('whoami')返回apache,apache是​​我参与这些函数的所有文件夹和文件的所有者。

请帮忙吗? 如果您有fred的imagemagick脚本的替代方案来生成过渡帧以生成视频,那么也将不胜感激。

2 个答案:

答案 0 :(得分:4)

使用Fred的ImageMagick脚本时遇到了这个问题。解决方案是使用您喜欢的编辑器(vim,nano等)更新脚本文件(scriptname.sh)并设置正确的临时目录。见下文:

# set directory for temporary files
dir="."    # suggestions are dir="." or dir="/tmp"
#

在我的情况下,temp directoy是“/ tmp”

# set directory for temporary files
dir="/tmp"    # suggestions are dir="." or dir="/tmp"
#

答案 1 :(得分:-1)

使用Fred的ImageMagick脚本中的textcleaner时,我遇到了这个问题。 解决方法是使用正确的路径tmp目录路径

在我的情况下

设置临时文件的目录

DIR =&#34; /无功/网络/ HTML / textcleaner /图像/&#34; #个建议是dir =&#34;。&#34;或者dir =&#34; / tmp&#34; #

这应该是可写的

textcleaner.sh也会转移到项目中。

相关问题