How to color text and background separately for Imagick title?

I only want to color the text of the inscription, and not the entire title (or background). Prior to Imagemagick 6.3.7, I could use this code for red text:

$im->newPseudoImage(300, 300, "caption:" . "Put your text" );
$im->colorizeImage('#ff0000',1.0);

I updated because I need to set the font and font size with the following code:

$im->setFont("somefont.ttf");
$im->setpointsize(72);

Now colorizeImage does not work as if it doesn’t "only color the text of the TEXT label, but the BACKGROUND header too ...!

For example, if I set black background and white text:

$im->newPseudoImage(300, 300, "caption:" . "Put your text" );
$im->setBackgroundColor('black');
$im->colorizeImage('white',1.0);

I have a white background behind white text or a white square (text color for the box)!

I tried different things, setBackgroundColor before or after colorizeImage, all the same ... I did a lot of research, but did not find anything else to color the header and background caption separately.

Anyone with an idea to help me? thanks in advance:)

+3
2

, , , :

$width = '600';
$height = '200';
$im = new Imagick();
$draw = new ImagickDraw();
$draw->setFont('arial.ttf');
$draw->setFontSize( 96 );
$fillcolor = new ImagickPixel( "white" );
$draw->setFillColor( $fillcolor );
$draw->setGravity( Imagick::GRAVITY_CENTER );
$bgcolor = new ImagickPixel( "black" );
$text = 'Rubblewebs';
$im->newImage($width, $height, $bgcolor );
$im->annotateImage($draw, 0, 0, 0, $text);
$im->setImageFormat("png");
$im->writeImage( 'text.png' );
0
  • . .
  • clutImage, . colorizeImage .
$im = new Imagick();
$im->newPseudoImage(300, 300, "caption:" . "Put your text" );
$im->setBackgroundColor('transparent');

$clut = new Imagick();
$clut->newImage(1, 1, new ImagickPixel('#ff0000'));
$txt->clutImage($clut);
$clut->destroy();
0

All Articles