【问题标题】:How do I change the color of a caption drawn with PHP Imagick's newPseudoImage function?如何更改使用 PHP Imagick 的 newPseudoImage 函数绘制的标题的颜色?
【发布时间】:2011-10-25 14:39:51
【问题描述】:

我正在使用Imagick::newPseudoImage 函数创建一个带有标题的图像,如下所示:

$txt = new Imagick();
$txt->setFont("templates/fonts/Gloria.ttf");
$txt->setGravity(imagick::GRAVITY_CENTER);
$txt->newPseudoImage( $image_width, $image_height, "caption:" . $text );

这会画一个黑色的标题。我想自定义这个标题的颜色。我知道还有其他使用 Imagick 绘制文本的方法。我需要使用带有标题的newPseudoImage 而不是这些其他方法,因为它会自动包装文本并调整其大小以适合给定的矩形。

【问题讨论】:

    标签: php imagemagick imagick


    【解决方案1】:

    colorizeImage 有问题会使文本稍微变暗,因为它与黑色混合在一起很有趣。请改用 clutImage

    $txt = new Imagick();
    $txt->setFont("templates/fonts/Gloria.ttf");
    $txt->setGravity(imagick::GRAVITY_CENTER);
    $txt->newPseudoImage( $image_width, $image_height, "caption:" . $text );
    
    $clut = new Imagick();
    $clut->newImage(1, 1, new ImagickPixel('#0000b0'));
    $txt->clutImage($clut);
    $clut->destroy();
    

    【讨论】:

      【解决方案2】:

      您可以使用 colorizeImage。我希望这可以帮助你:

      $im = new Imagick();
      $background = new ImagickPixel('none');
      
      $im->setBackgroundColor($background);
      $im->setFont("somefont.ttf");
      $im->setpointsize(72);
      
      $im->setGravity(Imagick::GRAVITY_CENTER);
      $im->newPseudoImage(300, 300, "caption:" . "Put your text" );
      $im->colorizeImage('#0000b0',1.0);
      $im->setImageFormat("png");
      
      header( "Content-Type: image/png" );
      echo $im;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-01-22
        • 1970-01-01
        • 2023-03-06
        • 1970-01-01
        • 1970-01-01
        • 2016-09-13
        • 2018-04-07
        • 2018-06-07
        相关资源
        最近更新 更多