[英]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可以解决任何相关问题的解决方案是使用以下小型实用程序:
这是一个基于GD的PHP类,但是有两个“无关紧要”的区别:
非常容易
总是完成工作
两天前,我遇到了类似的问题( 使用PHP将多个PNG图像合并为一个PNG ),但是该库可以节省一天的时间!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.