PHP创建透明PNG图

原文地址:http://www.jb51.net/article/51991.htm


经鉴定可用,代码如下:

<?php
/*  *$sourePic:原图路径  * $smallFileName:小图名称  * $width:小图宽  * $heigh:小图高  */
function pngthumb($sourePic, $smallFileName, $width, $heigh){
    $image = imagecreatefrompng($sourePic);//PNG
    imagesavealpha($image,true);//这里很重要 意思是不要丢了$sourePic图像的透明色;
    $BigWidth=imagesx($image);//大图宽度
    $BigHeigh=imagesy($image);//大图高度
    $thumb = imagecreatetruecolor($width,$heigh);
    imagealphablending($thumb,false);//这里很重要,意思是不合并颜色,直接用$img图像颜色替换,包括透明色;
    imagesavealpha($thumb,true);//这里很重要,意思是不要丢了$thumb图像的透明色;
    if(imagecopyresampled($thumb,$image,0,0,0,0,$width,$heigh,$BigWidth,$BigHeigh)){
        imagepng($thumb,$smallFileName);
    }
    return $smallFileName;//返回小图路径
}
pngthumb("001.png", "test2.png", 300, 300);//调用
echo '<div style="background-color: red;"><img src="test2.png"></div>';
?>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值