2010-01-23

imagemagick 文字轉圖片

imagemagick 中的 convert 可以把字型顯示在圖檔中

$convert [-display X-SERVER] {[-family FAMILY_NAME]|[-font FONT_PATH]} [-pointsize POINT_SIZE] label:STRING FILE_NAME

  • -display X-SERVER 向這裡指定的 X-SERVER 要求字型或圖片
  • -family FAMILY_NAME 使用指定的 font family 顯示文字
  • -font FONT_PATH 使用指定的 font 顯示文字 (name 是字型的路徑)
  • -pointsize POINT_SIZE 指定字型尺寸
  • -stretch STRETCH 指定字型的 stretch (Any,Condensed,Expanded,ExtraCondensed, ExtraExpanded,Normal...)
  • -style STYLE 指定字型的 style (Any,Italic,Normal,Oblique)
  • label:STRING STRING 代表圖檔內要顯示的文字
  • FILE_NAME 圖檔名稱

顯示系統安裝的字型清單

$ convert -list font
如果是 IM 6.3.5-7 之前,顯示字型清單要用
$ convert -list type

顯示支援的 font style

$ convert -list style

顯示支援的 font stretch

$ convert -list stretch

如果要顯示的字數較多,可在 label 指定要顯示的文字檔

$ convert -family Arial -pointsize 24 label:@font-test.txt font-test-arial.png

不曉得是我不會用,還是 imagemagick 有 bug,到目前為止,指定 -family 一直無法成功,但用 -font 指定字型路徑就沒問題。而指定了 -font 好像也就不要 -stretch 或 -style 了。

例:用 cwyen 顯示

旭日東昇,但依舊寒風刺骨
雪地上的屍體
見證著平民之女與甘願放棄優渥生活的阿乙之間
炙熱的愛
直到永遠

先將這段文字在目前所在的資料夾中存成文字檔 font-test-cht.txt
$ convert -font /usr/local/share/fonts/truetype/cwyen.ttf -pointsize 32 label:@font-test-cht.txt font-test-cht.png

$ display font-test-cht.png

如果要讓圖片更花俏,可:

加上色彩

-background BACKGROUND_COLOR
-fill FOREGROUND_COLOR
-list color (查詢內建的色彩關鍵字)

指定 size

-size WidthxHeight

在指定位置加上文字

-annotate +X+Y 'text'

字的輪廓加上外框 (加在 font 後面)

-stroke STROKE_COLOR
-strokewidth STROKE_WIDTH (不必指定單位,單位好像固定是 px ?)

圖片邊緣改為斜邊並加上光影

-raise WxH 左、上邊框亮,右、下邊框暗,W 是左、右邊框的寬度,H 是上、下邊框寬度
+raise WxH 左、上邊框暗,右、下邊框亮


其他花俏的東西以後有空再研究



參考資料

man convert
ImageMagick v6 Examples -- Text to Image Handling

Google Chrome 4 字型描繪尚待解決的幾個問題

最重大的當然就是 - 不理會 fontconfig 的設定,下面幾個 issues 可能是同一問題

  • Issue 18159: Chrome doesn't honor fontconfig settings

  • Issue 12179: System font hinting settings are not obeyed

  • Issue 29871: Chrome font rendering seems fuzzy compared to Firefox (on Linux)(這個 bug 有附比較多圖,其實,有些人家回報 chrome 太模糊的我反而覺得比較好看)

  • Issue 29817: font rendering
  • Issue 26206: Chrome doesn't respect fontconfig's hinting flags

另外,Chrome 對於字型 kerning 的解讀還需要加強 (相當有趣的發現!)

  • Issue 21207: Font rendering issue: kerning doesn't match Firefox

還有偽粗體的問題 (直接看 Issue 中的圖比較清楚)

  • Issue 22360: synthesized bold (fake bold) glyphs get horribly blurred when native bold is not availble

2010-01-11

限制 CPU 使用率的工具 - cpulimit

CPULIMIT



cpulimit 可限制指定程式的 CPU 使用率


在 Debian 中的安裝方式



# aptitude install cpulimit

語法簡介



$ sudo cpulimit [-e EXECUTABLE|-p PID|-P ABSOLUTE_PATH_TO_EXECUTABLE] [-l LIMIT]


  • 目標程式可用三種方式指定,用 -e 指定執行檔的名稱,用 -p 指定 PID,或 -P 指定絕對路徑

  • CPU 使用率的限制,用 -l 指定,-l 後面直接輸入整數即可,代表百分率


例子



限制 PID 為 10796 的 process CPU 使用率為 50%



$ sudo cpulimit -p 10796 -l 50
Process 10796 detected


限制 firefox 的 CPU 使用率為 50%



$ sudo cpulimit -e firefox-bin -l 50
Warning: no target process found. Waiting for it..


奇怪,抓不到?



$ ls -l /usr/lib/iceweasel/firefox-bin
lrwxrwxrwx 1 root root 31 2009-12-01 03:00 /usr/lib/iceweasel/firefox-bin -> ../xulrunner-1.9/xulrunner-stub


$ sudo cpulimit -e xulrunner-stub -l 50
Process 10796 detected


這次抓到了。所以,cpulimit 對 softlink 無效,必需找出 softlink 的 target。


參考資訊:


How To Limit CPU Usage Of A Process With cpulimit (Debian/Ubuntu)