imagecolorallocatealpha() 创建颜色值
需PHP4.3.2以上版本

解决方案 »

  1.   

    谢谢。
    刚刚测试了一下,结果不是令人满意,是不是我用错了?
    代码如下:
    <?php
    header ("Content-type: image/png");
    $im = @imagecreate (200,300)
        or die ("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocatealpha ($im, 0, 0, 0,0);
    imagepng ($im);
    imagedestroy ($im);
    ?>
    如果我将函数最后一个值设定为0,全黑。
    但是只要设置为大于0,就变成全白了,是我错误理解函数吗?
      

  2.   

    <?php
    header ("Content-type: image/gif"); // 有些浏览器不能识别image/png,这样写通用点
    $im = imagecreate (200,300);
    $background_color = ImageColorAllocate($im, 0,255,0); // 指派一个绿色
    imagecolortransparent($im,$background_color); // 设置为透明色,若注释掉该行则输出绿色的图
    imagepng ($im);
    imagedestroy ($im);
    ?>
      

  3.   

    <?php
    header ("Content-type: image/gif"); // 有些浏览器不能识别image/png,这样写通用点
    $im = imagecreate (200,300);
    $background_color = ImageColorAllocate($im, 0,255,0); // 指派一个绿色
    imagecolortransparent($im,$background_color); // 设置为透明色,若注释掉该行则输出绿色的图
    imagepng ($im);
    imagedestroy ($im);
    ?>
      

  4.   

    多谢楼主,小弟还有一件事请不明白:Png透明背景图只能网页透明?
    就是说,只能在网页里面透明的,一旦脱离了浏览器环境,就变成不透明的了。
    <?php
    header ("Content-type: image/gif"); // 有些浏览器不能识别image/png,这样写通用点
    $im = imagecreate (200,300);
    $background_color = ImageColorAllocate($im, 0,255,0); // 指派一个绿色
    imagecolortransparent($im,$background_color); // 设置为透明色,若注释掉该行则输出绿色的图
    $text_color = imagecolorallocate ($im, 233, 14, 91);
    imagestring ($im, 1, 5, 5,  "Test ", $text_color);
    imagepng ($im,"filename.png");
    imagedestroy ($im);
    ?>
    这是什么原理?
      

  5.   

    Fireworks是png的编辑软件,当然会显示出透明的了
      

  6.   

    对页面透明可以用imagecolorallocatealpha ()之类的函数,目前可能不支持渐变.
    图片内透明可以用索引点原色值与新色值叠加得到.
      

  7.   

    当我要图像重叠的时候怎么做?分别用ImageCopyResized拷入