PHP Imagick cannot set image background color

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 03:43:32

问题


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");

回答1:


First line of the code sets a new Imagickpixel object for the colors. Second line creates a new frame and 1920 and 1200 is ofcourse the dimensions.

$color = new ImagickPixel("white");

$input_img->newImage(1920,1200, $color)



回答2:


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);



回答3:


Try this!

$imput_img->setBackgroundColor(new ImagickPixel('blue'));


来源:https://stackoverflow.com/questions/13149812/php-imagick-cannot-set-image-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!