2012-10-02 49 views
1

我正在使用imagemagick調整上傳文件的大小,但在處理時我想向縮略圖通常顯示的用戶顯示一個旋轉的gif輪。我服務了大約7個大小的拇指,並希望輪子保持在32x32的大小中間,這就是簡單的一點。將gif添加到較大的背景

我需要知道的是,我能做到以上,同時仍保留了動畫

例子:

這個影像: This Image

在這個尺寸 This Size

啓動隨着動畫

回答

0

PHP中女巫的解決方案我使用水印GIF動畫圖片.... 它創建一個黑色bacground放在圖像上,然後把水印...

watermarkpath = 'path to wathermarkimage.jpg|gif|png'; 
$imagepath= 'path to the image';  
$watermark = new Imagick($watermarkpath); 
$GIF = new Imagick(); 
$GIF->setFormat("gif"); 

$animation = new Imagick($imagepath); 
foreach ($animation as $frame) { 

    $iWidth = $frame->getImageWidth(); 
    $iHeight = $frame->getImageHeight(); 
    $wWidth = $watermark->getImageWidth(); 
    $wHeight = $watermark->getImageHeight(); 

    if ($iHeight < $wHeight || $iWidth < $wWidth) { 
     // resize the watermark 
     $watermark->scaleImage($iWidth, $iHeight); 

     // get new size 
     $wWidth = $watermark->getImageWidth(); 
     $wHeight = $watermark->getImageHeight(); 
    } 

    $bgframe = new Imagick(); 
    $bgframe->newImage(($iWidth), ($iHeight + 80), new ImagickPixel('Black')); 
    $bgframe->setImageDelay($frame->getImageDelay()); 


    $x = ($iWidth) - $wWidth - 5; 
    $y = ($iHeight + 80) - $wHeight - 5; 


    $bgframe->compositeImage($frame, imagick::COMPOSITE_DEFAULT, 0, 0); 
    $bgframe->flattenImages(); 
    $bgframe->compositeImage($watermark, imagick::COMPOSITE_OVER, $x, $y); 
    $bgframe->flattenImages(); 
    $GIF->addImage($bgframe); 
} 



$GIF->writeimages($imagepath,true); 
1

檢查o UT斯達康這個小提琴,它可能包含你想要什麼:http://jsfiddle.net/TGdFB/1/

它使用jQuery的,但應該是很容易適應......

+0

我已經看了到使用一個CSS解決方案,但它不會與我們目前的代碼結構很好地工作。如果更重要,我可以保證進行更改並使用css/jquery,但這隻會在文件排隊時顯示,然後生成縮略圖。 –

+0

這可能會有所幫助,如果你會發布你已有的東西。你不想要任何JavaScript?處理圖像時肯定會有某種回調,或者如何交換圖像? * confused * – Mark

+0

那麼我想要做的只是生成這些文件只是一次,處理是由另一個進程從MySQL中的作業列表中讀取。考慮這個靜態圖像,以取代尚未生成的縮略圖。某些內容上傳可能是大型視頻文件,在生成圖像之前會轉換爲兩種不同格式,這可能需要一段時間,具體取決於幾個因素。因此,我不想在用戶瀏覽內容頁面時顯示黑色方塊,而是想顯示其中一個縮略圖。不過謝謝,我明白你想向我解釋的是什麼! –

1

弄成手動Photoshop中做不能夠找到這樣做的自動方式後這通過imagemagick。我找到了'coalesce'標誌,但沒有其他的東西。