0

長方形の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);
4

1 に答える 1

0

PHP GD に関連するほぼすべての問題の解決策は、この小さなユーティリティを使用することです。

http://phpimageworkshop.com/

これは GD に基づいた PHP クラスですが、2 つの「取るに足らない」違いがあります。

非常に簡単

常に仕事を終わらせる

2日前に同様の問題がありました(PHPを使用して複数のPNG画像を単一のPNGに結合します)が、このライブラリはその日を節約します!

于 2014-04-17T05:53:18.293 に答える