Black color of ImageMagick vignette?

☆樱花仙子☆ 提交于 2019-12-12 03:15:12

问题


PHP Imagemagick API has a vignette function: http://www.php.net/manual/en/imagick.vignetteimage.php

Great, but how do I get it with black color?


回答1:


Vignette's will default to the given image's background color. Altering this color is as simple as setting the image's background color before transforming the image with the Vignette effect.

<?php
$img = new Imagick("source.png");

$img->setImageBackgroundColor("black");
$img->vignetteImage(-5.0,15.0,15,15);

$img->writeImage("source_vignette.png");
$img->destroy();
exit();

Better yet. Use the ImagickPixel object for increased flexibility within your application.

<?php
$img = new Imagick("source.png");

$pixel = new ImagickPixel();

for($i=0;$i < 1; $i += 0.1) {
 $pixel->setHSL($i,0.5,0.5);
 $img->setImageBackgroundColor($pixel);
 $img->vignetteImage(-5.0,15.0,15,15);
 $img->writeImage("source_vignette_$i.png");
}

$pixel->destroy();
$img->destroy();
exit();


来源:https://stackoverflow.com/questions/17846665/black-color-of-imagemagick-vignette

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