0

我正在尝试通过复制背景并将其向下移动 1 像素和向右移动 1 像素来获取矩形 png 并使用 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 类......但它有两个“微不足道”的差异:

非常容易

总是把工作做好

两天前我有一个类似的问题(使用 PHP 将多个 PNG 图像连接成一个 PNG)但是这个库可以节省一天的时间!

于 2014-04-17T05:53:18.293 回答