2011-10-04 208 views
1

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

虽然imagemagick有反别名选项。但是,没有像photoshop这样的抗混叠类型。

有什么办法可以用imagemagick获得类似的强烈的反别名文本效果?

+0

要*其中*您指的许多Photoshop文本反别名类型之一?到目前为止你做了什么? – hakre

+0

我指的是这个页面描述的抗锯齿设置http://tutorialblog.org/photoshop-which-anti-alias-setting-is-best/ – pragnesh

+0

你的例子中有多个。例如,第一个变体应该支持开箱即用imagemagick,但我认为这不是你正在寻找的那个(没有变种),所以你正在寻找哪一个? – hakre

回答

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