php缩小png图片不损失透明色的解决方法
2013-12-25 16:08
831 查看
主要是利用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, 0, 0, 0, 127);
imagefill($newImg, 0, 0, $alpha);
//将源图拷贝到新图上,并设置在保存 PNG 图像时保存完整的 alpha 通道信息
imagecopyresampled($newImg, $srcImg, 0, 0, 0, 0, $newWidth, $newHeight, $srcWidth, $srcHeight);
imagesavealpha($newImg, true);
imagepng($newImg, './dst.png');
您可能感兴趣的文章:
相关文章推荐
- php缩小png图片不损失透明色的解决方法
- PHP缩小png图片,保留透明色方法
- PHP缩小png图片,保留透明色方法
- php缩小png图片时,不损失透明色的办法
- 解决png图片在IE6背景无法透明不兼容解决方法
- 使用DD_belatedPNG让IE6支持PNG透明图片 及IE6下背景图闪烁问题的解决方法
- IE6下png图片和背景图片透明问题解决方法
- 轻松解决PNG图片在IE6中背景不透明方法
- 解决IE6下透明PNG图片无法透明显示的方法
- png透明问题解决方法(png图片ie6不兼容问题)
- Android png透明图片转jpg时背景变黑的解决方法
- 基于jQuery IE6下PNG图片背景透明问题解决方法
- png透明图片,ie下的怪异模式,无法显示的解决方法
- PNG图片透明 IE6 解决方法
- IE6下png透明图片正常显示的解决方法
- IE6显示PNG图片背景透明的解决方法
- 解决在网页上显示PNG图片底色不透明的方法
- 解决IE6下PNG图片背景不透明的三种方法(CSS/JS/JQuery)
- 解决IE6下Png图片透明的最佳方法