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 6707297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:37:21+00:00 2026-05-26T07:37:21+00:00

I am working on a solution to automatically make an image of each word

  • 0

I am working on a solution to automatically make an image of each word of a large document that contains a complex script (Khmer in UTF-8). I’ve found Pango and Cairo which can render Khmer correctly. I’m not much of a programmer, so I started with the PHP versions of Pango and Cairo. But I am not sure how to break up a string and produce an image for each word automatically. There are no “real” spaces between words, just the Unicode character U+0200B (a zero-width space).

Would someone be willing to help me?

Here’s the code I am currently using that outputs the whole string:

<?php
header("Content-Type: image/png");
/* Make a 300x300px image surface */
$s = new CairoImageSurface(CairoFormat::ARGB32, 300, 300);
$c = new CairoContext($s);

/* Set the background to white */
$c->setSourceRGB(1, 1, 1);
$c->paint();

/* Let's draw using black 'ink' */
$c->setSourceRGB(0, 0, 0);

/* Make a Pango layout, set the font, then set the layout size */
$l = new PangoLayout($c);
$desc = new PangoFontDescription("KhmerOS Regular 28");
$l->setFontDescription($desc);
$l->setWidth(250 * PANGO_SCALE);

/* Here is the text */
$l->setMarkup("កាល​ដើម​ដំបូង​ឡើយ ព្រះ​បាន​បង្កើត​ផ្ទៃ​មេឃ និង​ផែនដី។");

/* Draw the layout on the surface */
$l->showLayout($c);

/* Output the PNG to the browser */
$s->writeToPng("php://output");
?>
  • 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-05-26T07:37:22+00:00Added an answer on May 26, 2026 at 7:37 am

    I figured it out using foreach:

    <?php
    //header("Content-Type: image/png");
    $str = "កាល​ដើម​ដំបូង​ឡើយ ព្រះ​បាន​បង្កើត​ផ្ទៃ​មេឃ និង​ផែនដី។";
    //$words = explode('​', $str);
    $words = preg_split('/ |​/', $str);
    
    $i=1;
    foreach($words as $word) {
    /* Make a 300x300px image surface */
    $s = new CairoImageSurface(CairoFormat::ARGB32, 300, 300);
    $c = new CairoContext($s);
    
    /* Set the background to white */
    $c->setSourceRGB(1, 1, 1);
    $c->paint();
    
    /* Let's draw using black 'ink' */
    $c->setSourceRGB(0, 0, 0);
    
    /* Make a Pango layout, set the font, then set the layout size */
    $l = new PangoLayout($c);
    $desc = new PangoFontDescription("KhmerOS Regular 28");
    $l->setFontDescription($desc);
    $l->setWidth(250 * PANGO_SCALE);
    
    
    /* Here, we use Pango markup to make part of the text bold */
    
    
    
    $i++;
    
    $l->setMarkup($word);
    
    /* Draw the layout on the surface */
    $l->showLayout($c);
    
    /* Output the PNG to the browser */
    //$s->writeToPng("php://output");
    $s->writeToPng(dirname(__FILE__) . '/test'.$i.'.png');
    echo $img = "<img src=\"test".$i.".png\">";
    echo $i;
    }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a solution that has two projects: One ASP.NET web application, and
Capistrano is a great solution for building scripts that automatically deploy a website and/or
I am working on an application that runs a service. This service starts automatically
I'm working in a Java project where I need to make automatically an application
I'm currently working on a solution to automatically generate ExtJS forms based on a
I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a
Has anyone else had this issue and found a working solution? I've enabled the
Im searching for the best practice (or any working solution) for the following scenario:
Good day. Has somebody working solution for deleting asset in nested form in Carrierwave?
I want to convert a C-style string into a byte-vector. A working solution would

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.