首頁  >  文章  >  後端開發  >  imagemagic設定字體​​問題

imagemagic設定字體​​問題

WBOY
WBOY原創
2016-08-25 10:37:311668瀏覽

虛擬機器中我已安裝imagick元件,以及要用到的字型。
如圖:
imagemagic設定字體​​問題

imagick畫圖部分代碼如下:

<code>
$imagick = new Imagick($template_image);
$draw = new ImagickDraw();
$draw->setFillColor('black');
$draw->setFont('/usr/share/fonts/wqy-microhei.ttc');
$draw->settextencoding('utf-8');
$draw->setFontSize(30);
imagick_add_text($imagick,$draw,"测试", 302, 688, 130,'#33BAF6');</code>

寫字函數:

<code>function imagick_add_text(&$imagick, &$draw, $text, $x = 0, $y = 0, $font_size = 12, $fill_color = 0, $text_kerning = 0) {
    if (isset($font_size))
        $draw->setFontSize($font_size);
    if (isset($fill_color))
        $draw->setFillColor($fill_color);
    if (isset($text_kerning))
        $draw->setTextKerning($text_kerning);
    $imagick->annotateImage($draw, $x, $y, 0, $text);
}</code>

現在的問題是,$draw->setFont()這一步是沒有報錯的,說明字體設定成功了,但是$imagick->annotateImage() 也就是畫圖這一步出錯了。
為什麼,是字體問題嗎?

註:
1.我使用的是vagrant虛擬環境進行開發。
2.測試環境中安裝了相同的字體,並且使用imagick畫圖寫字成功。 (測試環境字體是維運人員裝的)

回覆內容:

虛擬機器中我已安裝imagick元件,以及要用到的字型。
如圖:
imagemagic設定字體​​問題

imagick畫圖部分代碼如下:

<code>
$imagick = new Imagick($template_image);
$draw = new ImagickDraw();
$draw->setFillColor('black');
$draw->setFont('/usr/share/fonts/wqy-microhei.ttc');
$draw->settextencoding('utf-8');
$draw->setFontSize(30);
imagick_add_text($imagick,$draw,"测试", 302, 688, 130,'#33BAF6');</code>

寫字函數:

<code>function imagick_add_text(&$imagick, &$draw, $text, $x = 0, $y = 0, $font_size = 12, $fill_color = 0, $text_kerning = 0) {
    if (isset($font_size))
        $draw->setFontSize($font_size);
    if (isset($fill_color))
        $draw->setFillColor($fill_color);
    if (isset($text_kerning))
        $draw->setTextKerning($text_kerning);
    $imagick->annotateImage($draw, $x, $y, 0, $text);
}</code>

現在的問題是,$draw->setFont()這一步是沒有報錯的,說明字體設定成功了,但是$imagick->annotateImage() 也就是畫圖這一步出錯了。
為什麼,是字體問題嗎?

註:
1.我使用的是vagrant虛擬環境進行開發。
2.測試環境中安裝了相同的字體,並且使用imagick畫圖寫字成功。 (測試環境字體是維運人員裝的)

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn