在imagecopy前用ImageColorTransparent设置源资源的透明色

解决方案 »

  1.   

    设置了呀!但是最终保存的temp.png文件还是无效。
      

  2.   

    设置了呀!但是最终保存的temp.png文件还是没有透明背景,而是纯白的背景。
      

  3.   

    <?
    header ("Content-type: image/png");// 加载图片资源
    $Back0 = imagecreatefrompng("./Back0.png");// 创建临时图片
    $tempimage = imagecreatetruecolor (100,100);
    $white=imagecolorallocate($tempimage,255,255,255); 
    $black=imagecolorallocate($tempimage,0,0,0); 
    $red=imagecolorallocate($tempimage,255,0,0); 
    imagecopy($tempimage,$Back0,0,0,0,0,90,80);
    imagefill($tempimage,0,0,$red); 
    imagecolortransparent($tempimage,$red);
    // 根据临时图片创建图片文件
    imagepng($tempimage,"test.png");
    imagepng($tempimage);
    // 销毁图片资源
    imagedestroy($Back0);
    imagedestroy($tempimage);
    ?>
      

  4.   

    to:love01px(JAVA CUP) 
    这样创建出来的图片文件还是没有透明的背景。
      

  5.   

    真有你的!1、的确,你有imagecolortransparent($tempimage,$white);
    但是请注意:$tempimage的部分或全部将要被$Back0覆盖,而$Back0并没有设置通明色!
    所以我说的是“设置源资源的透明色”
    $tempimage是目标,而$Back0才是源2、由于$Back0是载入的图片,并不能通过
    $white=imagecolorallocate($Back0,255,255,255); 
    imagecolortransparent($Back0,$white);
    来设置通明色,因为创建的颜色只是附加在原图片调色板之后。
    而你需要设置的是:原来是透明的,装入后转为白色的那个颜色索引
    你需要用
    $white=imagecolorclosest($Back0,255,255,255);
    取得
      

  6.   

    IE对png支持不好
    上面的程序用firefox能正常显示推荐你改用gif做透明图片
      

  7.   

    <?
    header ("Content-type: image/png");// 加载图片资源
    $Back0 = imagecreatefrompng("Back_0.png");// 创建临时图片
    $TempImage = @imagecreatetruecolor (200,200) or die ("Cannot Initialize new GD image stream");
    $TransparentColor=imagecolorallocate($TempImage,255,0,255); 
    imagefill($TempImage,0,0,$TransparentColor);
    imagecolortransparent($TempImage,$TransparentColor);$TransparentColor=imagecolorclosest($Back0,255,0,255);
    imagecolortransparent($Back0,$TransparentColor);imagecopy($TempImage,$Back0,0,0,0,0,100,100);// 根据临时图片创建图片文件
    imagepng($TempImage,"aaa.png");// 销毁图片资源
    imagedestroy($Back0);
    imagedestroy($TempImage);
    ?>
    <img src="aaa.png" />改成了这个,但是aaa.png的背景还不是透明的。偶已经有点晕了。