簡體   English   中英

使用php shell_exec()觸發時,ImageMagick unix shell腳本不起作用

[英]ImageMagick unix shell script doesn't work when fired with php shell_exec()

我必須使用Fred的ImageMagick腳本創建一個圖像轉換序列,特別是fx過渡

在我的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

因為沒有生成圖片(它顯示編號框架的算法是正確的,所以不要專注於那個)。

如果我打開服務器上的終端,使用ssh連接並運行該命令,它會給我同樣的錯誤,除非我使用sudo。 如果我在php shell_exec上使用sudo,它將不會執行。 shell_exec('whoami')返回apache,apache是​​我參與這些函數的所有文件夾和文件的所有者。

有些幫助嗎? 如果您有fred的imagemagick腳本的替代方案來生成過渡幀以生成視頻,那么也將不勝感激。

我在使用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"
#

當我使用Fred的ImageMagick腳本中的textcleaner時,我遇到了這個問題。 解決方法是使用正確的路徑tmp目錄路徑

在我的情況下

設置臨時文件的目錄

dir =“/ var / www / html / textcleaner / images /”#advice is dir =“。” 或者dir =“/ tmp”#

這應該是可寫的

textcleaner.sh也將移動到該項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM