Created
November 8, 2016 10:40
-
-
Save bytespider/6e07a82edd3ce2693a007cd0aa8af93d to your computer and use it in GitHub Desktop.
Setting the background colour of a transparent PNG when converted to JPEG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$image = new Imagick('kiwi.png'); // https://s13.postimg.org/hakfstg1j/kiwi.png | |
$image->setImageBackgroundColor(new ImagickPixel('white')); // set the background color of the image | |
$image->setImageAlphaChannel(Imagick::ALPHACHANNEL_BACKGROUND); // ALPHACHANNEL_BACKGROUND is undocumented and has a value of 2 | |
// save a JPEG | |
$image->setImageFormat('jpeg'); | |
$image->setImageCompression(Imagick::COMPRESSION_JPEG); | |
$image->setImageCompressionQuality(80); | |
$image->writeImage('kiwi.jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment