Home > Backend Development > PHP Tutorial > imagemagic setting font problem

imagemagic setting font problem

WBOY
Release: 2016-08-25 10:37:31
Original
1760 people have browsed it

I have installed the imagick component in the virtual machine, as well as the fonts to be used.
As shown in the picture:
imagemagic setting font problem

Imagick drawing part code is as follows:

<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>
Copy after login
Copy after login

Writing function:

<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>
Copy after login
Copy after login

The problem now is that there is no error in the $draw->setFont() step, indicating that the font setting is successful, but $imagick->annotateImage() that is, there is an error in the drawing step.
Why, is it a font problem?

Note:
1. I use the vagrant virtual environment for development.
2. The same font is installed in the test environment, and Imagick can be used to draw and write successfully. (The test environment fonts are installed by operation and maintenance personnel)

Reply content:

I have installed the imagick component in the virtual machine, as well as the fonts to be used.
As shown in the picture:
imagemagic setting font problem

Imagick drawing part code is as follows:

<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>
Copy after login
Copy after login

Writing function:

<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>
Copy after login
Copy after login

The problem now is that there is no error in the $draw->setFont() step, indicating that the font setting is successful, but $imagick->annotateImage() that is, there is an error in the drawing step.
Why, is it a font problem?

Note:
1. I use the vagrant virtual environment for development.
2. The same font is installed in the test environment, and Imagick can be used to draw and write successfully. (The test environment fonts are installed by operation and maintenance personnel)

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template