2011-10-04 151 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();