PHP/GD - transparent background

前端 未结 1 2028
陌清茗
陌清茗 2020-12-02 21:48

I want to do the following in PHP in combination with GD. ImageMagick is not an option, unfortunately, but this seems like such a common problem that there has to b

相关标签:
1条回答
  • 2020-12-02 22:01

    imagecolortransparent is probably not what you want here if you're merging images, as single-colour transparency is nasty.

    Instead, try it with a transparent fill mask like so:

    <?php
    $image = imagecreatetruecolor(100, 100);
    
    // Transparent Background
    imagealphablending($image, false);
    $transparency = imagecolorallocatealpha($image, 0, 0, 0, 127);
    imagefill($image, 0, 0, $transparency);
    imagesavealpha($image, true);
    
    // Drawing over
    $black = imagecolorallocate($image, 0, 0, 0);
    imagefilledrectangle($image, 25, 25, 75, 75, $black);
    
    header('Content-Type: image/png');
    imagepng($image);
    
    0 讨论(0)
提交回复
热议问题