如何为Imagick字幕分别着色文本和背景? [英] How to color text and background separatly for Imagick caption?

查看:156
本文介绍了如何为Imagick字幕分别着色文本和背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想给字幕文本加上颜色,而不是整个字幕框(或背景). 在Imagemagick 6.3.7之前,我可以使用以下代码来显示红色文本:

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

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

I have upgraded because I need to set a font and a font size with the following code :

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

现在colorizeImage不能以相同的方式工作,因为它不仅为字幕TEXT着色,而且为Background字幕也着色..!

Now colorizeImage does not work the same way, as it doesnt' color only the caption TEXT but the caption BACKGROUND also ..!

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

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

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

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

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

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

I tried different things, setBackgroundColor before or after colorizeImage, still the same... I've made lots of researches but found nothing else to color the caption and the background caption separately.

有人想帮助我吗?提前致谢:)

Anybody with an idea to help me ? Thx in advance :)

推荐答案

  1. 您想要透明背景.然后,您将只为前景着色.
  2. 使用 clutImage 来应用颜色. colorizeImage 存在替换黑色时应用略深的颜色的问题.
  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();

这篇关于如何为Imagick字幕分别着色文本和背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆