Imagemagick 抗锯齿文本

发布于 2024-12-07 20:51:00 字数 127 浏览 0 评论 0原文

Photoshop 具有很强的抗锯齿文字效果。

虽然 imagemagick 有抗锯齿选项。但是,没有像Photoshop那样的抗锯齿类型。

有没有办法用 imagemagick 获得类似的强抗锯齿文本效果?

photoshop has strong anti-alias text effect.

Although imagemagick has anti-alias option. but, does not have anti-alias type like photoshop.

is there any way to get similar strong anti-alias text effect with imagemagick ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

め七分饶幸 2024-12-14 20:51:00

这不是一个完美的解决方案(我只是自己学习这个),但它会让你接近:你可以打印更大的文本并以你选择的任何大小添加笔划,然后缩小它。示例代码:

$template_file= "blank.png"; // a transparent png
$template_blob = file_get_contents($template_file);
$width = 100;
$height = 50;
$mult = 6;
$template = new imagick();
$template->readImageBlob($template_blob);
$template->setImageDepth(8);
$template->setCompressionQuality(100); 
$template->setCompression(Imagick::COMPRESSION_NO);
$template->setImageFormat("png");


$points = array( 
   $mult, //scale by which you enlarge it
   0 //# rotate
);

$template->distortImage( imagick::DISTORTION_SCALEROTATETRANSLATE, $points, TRUE ); 

$color = '#000000';

$draw = new ImagickDraw();
$pixel = new ImagickPixel('none');
$draw->setFont('Arial.ttf');
$draw->setFontSize($font_size*$mult);
$draw->setFillColor($color);
$draw->setStrokeColor($color);
$draw->setStrokeWidth(1);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
$draw->settextkerning($mult); // adjust the kerning if you like

$template->annotateImage($draw, $x_indent, $y_indent, $some_angle, $text);

$points = array( 
   1/$mult, // set it back to the original scale
    0 // rotate
);

$template->distortImage( imagick::DISTORTION_SCALEROTATETRANSLATE, $points, TRUE ); 

 //Do something with the $template here like:
 $template->writeImage("test.png");

$template->clear();
$template->destroy();
$draw->clear();
$draw->destroy();

It's not a perfect solution (I'm just learning this myself) but it will get you close: You can print the text larger and add a stroke at whatever size you choose then shrink it down after. Example code:

$template_file= "blank.png"; // a transparent png
$template_blob = file_get_contents($template_file);
$width = 100;
$height = 50;
$mult = 6;
$template = new imagick();
$template->readImageBlob($template_blob);
$template->setImageDepth(8);
$template->setCompressionQuality(100); 
$template->setCompression(Imagick::COMPRESSION_NO);
$template->setImageFormat("png");


$points = array( 
   $mult, //scale by which you enlarge it
   0 //# rotate
);

$template->distortImage( imagick::DISTORTION_SCALEROTATETRANSLATE, $points, TRUE ); 

$color = '#000000';

$draw = new ImagickDraw();
$pixel = new ImagickPixel('none');
$draw->setFont('Arial.ttf');
$draw->setFontSize($font_size*$mult);
$draw->setFillColor($color);
$draw->setStrokeColor($color);
$draw->setStrokeWidth(1);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);
$draw->settextkerning($mult); // adjust the kerning if you like

$template->annotateImage($draw, $x_indent, $y_indent, $some_angle, $text);

$points = array( 
   1/$mult, // set it back to the original scale
    0 // rotate
);

$template->distortImage( imagick::DISTORTION_SCALEROTATETRANSLATE, $points, TRUE ); 

 //Do something with the $template here like:
 $template->writeImage("test.png");

$template->clear();
$template->destroy();
$draw->clear();
$draw->destroy();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文