繁体   English   中英

PHP中的图片叠加层; 黑色背景?

[英]Image Overlay in PHP; Black Background?

当我使用GD库在php中执行图像叠加时,总是得到黑色背景,但是,所有图像均正确叠加。 有人可以帮忙吗?

<?php

    $images = array( $_GET['color'], $_GET['face'], $_GET['hat'] );


    $img = imagecreatetruecolor(58, 75);

    imagealphablending($img, true);
    imagesavealpha($img, true);

    imagecolorallocate($img, 255, 205, 255);
    imagecolorallocate($img, 255, 255, 255);
    imagecolortransparent($img, $white);

imagefilledrectangle($img, 0, 0, $imgWidth, $imgHeight, $white);
    foreach($images as $fn) {

        $cur = imagecreatefrompng($fn);
        imagealphablending($cur, true);
        imagesavealpha($cur, true);


        imagecopy($img, $cur, 0, 0, 0, 0, 58, 75);


        imagedestroy($cur);
    }   


    header('Content-Type: image/png');
    imagepng($img);

?>
// Create an image

$img = imagecreatetruecolor($imgWidth, $imgHeight);

$white = imagecolorallocate($img, 255, 255, 255);

// Make the background white

imagefilledrectangle($img, 0, 0, $imgWidth, $imgHeight, $white);

...有帮助。

这是一个常见的问题,并且在堆栈溢出时已经有答案了; 那里的答案可以完美地解决问题。 您可能想尝试更难的搜索:)

我建议您通过使用功能更强大(但不幸的是文献记录不多 )的imagick库来使您的生活更轻松,如果您要尝试执行除最基本的图像操作以外的任何操作; 它更快,更容易(同样,一旦您通过文档后)并且功能更强大。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM