سؤال

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?

هل كانت مفيدة؟

المحلول

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

enter image description here

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();
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top