簡體   English   中英

使用GD和PHP的PNG合成

[英]PNG composition using GD and PHP

我正在嘗試采用矩形png,並通過復制背景並將其下移1個像素並向右移動1個像素來使用GD添加深度。 我也在努力保持透明的背景。

我在保持透明度方面遇到了很多麻煩。

任何幫助將不勝感激。

謝謝!

    $obj = imagecreatefrompng('rectangle.png');
    $depth = 5;
    $obj_width = imagesx($obj);  
    $obj_height = imagesy($obj); 
    imagesavealpha($obj, true); 
        for($i=1;$i<=$depth;$i++){
            $layer = imagecreatefrompng('rectangle.png');
            imagealphablending( $layer, false );
            imagesavealpha($layer, true);

            $new_obj = imagecreatetruecolor($obj_width+$i,$obj_height+$i);
            $new_obj_width = imagesx($new_obj);  
            $new_obj_height = imagesy($new_obj); 
            imagealphablending( $new_obj, false );
            imagesavealpha($new_obj, true);

            $trans_color = imagecolorallocatealpha($new_obj, 0, 0, 0, 127);
            imagefill($new_obj, 0, 0, $trans_color);

            imagecopyresampled($new_obj, $layer, $i, $i, 0, 0, $obj_width, $obj_height, $obj_width, $obj_height);
            //imagesavealpha($new_obj, true); 
            //imagesavealpha($obj, true); 
        }
    header ("Content-type: image/png");
    imagepng($new_obj);
    imagedestroy($new_obj);

實際上,使用PHP GD可以解決任何相關問題的解決方案是使用以下小型實用程序:

http://phpimageworkshop.com/

這是一個基於GD的PHP類,但是有兩個“無關緊要”的區別:

非常容易

總是完成工作

兩天前,我遇到了類似的問題( 使用PHP將多個PNG圖像合並為一個PNG ),但是該庫可以節省一天的時間!

暫無
暫無

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

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