English 中文(简体)
如何为 Imagick 标题单独颜色文本和背景?
原标题:How to color text and background separatly for Imagick caption?

I only want to color the caption text, and not the entire caption box (or background). Before Imagemagick 6.3.7 I could use this code to have a red colored text :

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

我升级了,因为我需要设置字体和字体大小,代码如下:

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

现在彩色图像不工作方式相同, 因为它不只彩色标题 TEXT, 而且还彩色标题背景...!! @ label

例如,如果我设置黑背景和白文字:

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

白文字后面有白色背景, 或白盒子后面有白色背景( 白文字的颜色)!

我尝试过不同的东西, 在彩色图像之前或之后设置背景颜色, 仍然相同... 我做了很多研究, 但没有发现其他东西可以单独显示标题和背景说明 。

有人想帮我吗?

问题回答
  1. You want a transparent background. Then you will only color the foreground.
  2. Use clutImage to apply the color. colorizeImage has issues with applying a slightly darker color when replacing black.
$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();

不知道这是不是你想要的,但这让我在黑色背景上看到白文字:

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




相关问题
phpThumb cannot find ImageMagick / Imagick

I m having a problem with phpThumb. It says in the documentation that to get the best out of it, use ImageMagick / Imagick. I ve got this installed on the Server (running Centos 5.1), and can run ...

Properly converting a CMYK image to RGB with RMagick

I have been using the below to do a color conversion if @image.colorspace == Magick::CMYKColorspace # @image.colorspace #=> CMYKColorspace=12 @image.colorspace = Magick::...

Imagemagick convert pdf to png

I am rather new to using the command line and php. That being said I have been trying to figure out how to use ImageMagick with the exec() function. I have this currently, $command="/usr/local/lib/...

ImageMagick failing to convert to JPG

We recently installed the latest version of ImageMagick onto our Linux server. I seem to be having issues performing the most basic of tasks. I am running this command line: /usr/bin/convert /...

热门标签