Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8139603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:52:50+00:00 2026-06-06T11:52:50+00:00

I need to annotate an image with Chinese Text and I am using Imagick

  • 0

I need to annotate an image with Chinese Text and I am using Imagick library right now.

An example of a Chinese Text is

这是中文

The Chinese Font file used is this

The file originally is named 华文黑体.ttf

it can also be found in Mac OSX under /Library/Font

I have renamed it to English STHeiTi.ttf make it easier to call the file in php code.

In particular the Imagick::annotateImage function

I also am using the answer from “How can I draw wrapped text using Imagick in PHP?”.

The reason why I am using it is because it is successful for English text and application needs to annotate both English and Chinese, though not at the same time.

The problem is that when I run the annotateImage using Chinese text, I get annotation that looks like 罍

Code included here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T11:52:52+00:00Added an answer on June 6, 2026 at 11:52 am

    Full solution here:

    https://gist.github.com/2971092/232adc3ebfc4b45f0e6e8bb5934308d9051450a4

    Key ideas:

    Must set the html charset and internal encoding on the form and on the processing page

    header('Content-Type: text/html; charset=utf-8');
    mb_internal_encoding('utf-8');
    

    These lines must be at the top lines of the php files.

    Use this function to determine if text is Chinese and use the right font file

    function isThisChineseText($text) {
        return preg_match("/\p{Han}+/u", $text);
    }
    

    For more details check out https://stackoverflow.com/a/11219301/80353

    Set TextEncoding properly in ImagickDraw object

    $draw = new ImagickDraw();
    
    // set utf 8 format
    $draw->setTextEncoding('UTF-8');
    

    Note the Capitalized UTF. THis was helpfully pointed out to me by Walter Tross in his answer here: https://stackoverflow.com/a/11207521/80353

    Use preg_match_all to explode English words, Chinese Words and spaces

    // separate the text by chinese characters or words or spaces
    preg_match_all('/([\w]+)|(.)/u', $text, $matches);
    $words = $matches[0];
    

    Inspired by this answer https://stackoverflow.com/a/4113903/80353

    Works just as well for english text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to overlay an image with some text using PyObjC, while striving to
Need to insert selected text on the page into textarea. There must be some
Need some help to solve this. I have a gridview and inside the gridview
I have over a thousand POJOs, the properties of which, I need to annotate
The problem is that I need to create in runtime a class like this:
I need to create a join table in my database using JPA annotations so
I have few classes that I need to annotate with a name so I
I created this plot with ggplot2 : The outside lines need to correspond to
Need: take in XML and save data to database. Currently using: JAXB to convert
I need some tool to display text containing ANSI codes correctly on Windows. No

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.