photoshop具有很强的抗别名文字效果。
虽然imagemagick有反别名选项。但是,没有像photoshop这样的反别名类型。
有没有办法用imagemagick获得类似的强抗锯齿文字效果?
答案 0 :(得分:0)
这不是一个完美的解决方案(我只是自己学习),但它会让你接近:你可以打印更大的文字并添加你选择的任何尺寸的笔划然后缩小它。示例代码:
$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();