Transparent to white in Imagick for PHP

后端 未结 10 1666
暗喜
暗喜 2020-12-16 11:58

I have a png image with a transparent background and I want to convert it to a jpg image with a white background.

The code is basically this:

$image          


        
10条回答
  •  旧时难觅i
    2020-12-16 12:35

    You can try it by changing Imagick constant as shown below

    //$image will conatains image which needs background to be transparent
    $white = new Imagick();
    
    $white->newImage($image->getImageWidth(), $image->getImageHeight(), new ImagickPixel( "white" ));
    $white->compositeimage($image, Imagick::COMPOSITE_DEFAULT, $x1OfTransparentImage, $y1OfTransparentImage,);
    $white->flattenImages();
    $white->writeImage('opaque.jpg');    
    
    $white->destroy();
    

提交回复
热议问题