【问题标题】:How to color text and background separatly for Imagick caption?如何为 Imagick 标题分别着色文本和背景?
【发布时间】:2012-05-25 07:34:29
【问题描述】:

我只想为标题文本着色,而不是整个标题框(或背景)。 在 Imagemagick 6.3.7 之前,我可以使用此代码来显示红色文本:

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

我已升级,因为我需要使用以下代码设置字体和字体大小:

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

现在 colorizeImage 的工作方式不同了,因为它不仅为标题 TEXT 着色,而且还为标题背景着色 ..!

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

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

我在白色文本或白色框(框的文本颜色)后面有一个白色背景!

我尝试了不同的东西,setBackgroundColor 在 colorizeImage 之前或之后,还是一样...我做了很多研究,但没有发现其他方法可以分别为标题和背景标题着色。

有人有想法可以帮助我吗?提前谢谢:)

【问题讨论】:

    标签: imagemagick imagick caption


    【解决方案1】:
    1. 您需要透明背景。然后你只会给前景着色。
    2. 使用 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();
    

    【讨论】:

      【解决方案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' );
      

      【讨论】:

        猜你喜欢
        • 2019-12-21
        • 1970-01-01
        • 2022-01-13
        • 2018-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-02-20
        • 2020-11-13
        相关资源
        最近更新 更多