php add a picture onto another

后端 未结 1 839
挽巷
挽巷 2020-12-22 11:27

I would like to change the color of an image with php. if I wanted to make it appear redder applicherei an image on a higher level across an image with a transparent red and

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

    You can try using GD's imagecopymerge function, which copies one image to another and supports alpha transparency. Something like this should work:

    <?php
    $redimg = imagecreatetruecolor(100, 100);
    $image = imagecreatefrompng('image.png');
    
    // sets background to red
    $red = imagecolorallocate($redimg, 255, 0, 0);
    imagefill($redimg, 0, 0, $red);
    
    // Merge the red image onto the PNG image
    imagecopymerge($image, $redimg, 0, 0, 0, 0, 100, 100, 75);
    
    header('Content-type: image/png');
    imagepng($image);
    imagedestroy($image);
    imagedestroy($redimg);
    ?>
    

    There's more information here.

    0 讨论(0)
提交回复
热议问题