I load transparent png image and i every time i try to set bg color using setimagebackgroundcolor() it still transparent
$input_img = new Imagick();
$input_img->setBackgroundColor("#ff0000");
$input_img->readImage("transparent.png");
$input_img->setimagebackgroundcolor("#00ff00");
$input_img->setImageFormat("png");
$input_img->setimagebackgroundcolor("#ff00ff");
$input_img->writeimage("image.png");
The trick is using: $im = $im->flattenImages();:
<?php
$im = new Imagick($filename);
$im->setImageBackgroundColor('#ffffff');
$im = $im->flattenImages();
$im->setImageFormat("jpeg");
$im->setImageCompressionQuality(95);
$im->writeImage($filename);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With