|
主要是利用gd库的两个方法: 代码如下:imagecolorallocatealpha //分配颜色 + alpha
imagesavealpha //设置在保存 png 图像时保存完整的 alpha 通道信息
代码示例:
代码如下://获取源图gd图像标识符 $srcImg = imagecreatefrompng('./src.png'); $srcWidth = imagesx($srcImg); $srcHeight = imagesy($srcImg);
//创建新图 $newWidth = round($srcWidth / 2); $newHeight = round($srcHeight / 2); $newImg = imagecreatetruecolor($newWidth,$newHeight); //分配颜色 + alpha,将颜色填充到新图上 $alpha = imagecolorallocatealpha($newImg,127); imagefill($newImg,$alpha);
//将源图拷贝到新图上,并设置在保存 PNG 图像时保存完整的 alpha 通道信息 imagecopyresampled($newImg,$srcImg,$newWidth,$newHeight,$srcWidth,$srcHeight); imagesavealpha($newImg,true); imagepng($newImg,'./dst.png');
(编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|