2009-07-11 16 views
0

我試圖在每個循環之後都有這個函數輸出數據和重新調整後的圖像,但是直到循環完成數組後才顯示任何內容。我假設這與PHP圖像功能有關,但有沒有解決方法?PHP圖像GD庫直到循環完成才輸出視覺效果

function resize_images($images_l){ 
echo "Resizing Images<br>"; 
$new_height = 200; 
$new_width = 200; 
$c = 1; 

foreach($images_l as $filename) { 
    echo "Image" . $c . "<br>"; 
    $c++; 


    // Get the new dimensions 
    list($width, $height) = getimagesize($filename); 
    echo $new_width . ", " . $new_height . "<br>"; 

    // Create the new image 
    $image_blank = imagecreatetruecolor($new_width, $new_height); 
    $baseimage = imagecreatefromjpeg($filename); 
    imagecopyresampled($image_blank, $baseimage, 0, 0, 0, 0, $new_width, $new_height, $width, $height); 

    // Save the file 
    imagejpeg($image_blank, 's_' . $filename , 100); 

    echo "<img src=\"s_$filename\">"; 
} 
return TRUE; } 

感謝

回答

1

我建議你看看Output Control Functions,你可以刷新每個圖像後重新縮放。

<?php 

function gradual_output() 
{ 
    # start using the output buffer. 
    ob_start(); 

    for ($i = 0; $i <= 10; $i++) { 
     echo "loop count: " . $i . "<br />\n"; 

     # flush the buffer to the user. 
     ob_flush(); flush(); 

     # do something that takes a while... 
     sleep(2); 
    } 

    # were done with the buffer, clean up. 
    ob_end_clean(); 
} 

gradual_output(); 

?> 

你叫ob_start()將被放入緩衝區,你可以決定何時要刷新該緩衝區給用戶之後回聲出任何東西。

0

我想這是你的Web服務器上?當服務器運行完畢後,您的服務器只會向客戶端發送一次網頁。如果你想顯示所有的中間階段,你需要建立一個頁面,自動刷新或使用JavaScript重新加載圖像的時間間隔。

如果這是在CLI上,那麼你如何查看圖像。你的帖子沒有意義。

+0

對不起,這將在我自己的本地機器上運行。當然,AJAX會很好,但同時我會如何在每個循環後刷新頁面? – user103219 2009-07-11 01:22:10

+0

@razass:看起來非常清楚,丹尼斯說這個頁面只發送給客戶端,因此通過php進行增量更改是不可能的。使用jQuery實現這將是一個笑話,最多需要5分鐘。 – tomzx 2009-07-11 04:16:30