Transparent to white in Imagick for PHP

后端 未结 10 1646
暗喜
暗喜 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条回答
  •  独厮守ぢ
    2020-12-16 12:47

    I ran into the same problem when converting PDFs to PNGs, and I used flattenImages().

            //get the first page of the PDF
            $im = new imagick( $file.'[0]' );
    
            //set the background to white
            $im->setImageBackgroundColor('white');
    
            //flatten the image
            $im = $im->flattenImages(); 
    
            //do the rest of the image operations
            $im->setResolution( 181, 181 );
            $im->setCompressionQuality(100);
            $im->resizeImage ( 181, 181,  imagick::FILTER_LANCZOS, 1, TRUE);
            $im->setImageFormat('png');
            $imageName = $title.'_thumb.png';
    

提交回复
热议问题