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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:59:55+00:00 2026-05-16T09:59:55+00:00

I am taking an xml feed and creating an image from the text. What

  • 0

I am taking an xml feed and creating an image from the text. What I would like to do it color the link text a different color than the regular text. I am looping through the text to find the link, but cannot figure out how to color that text.

  • 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-16T09:59:55+00:00Added an answer on May 16, 2026 at 9:59 am

    imagetttftext() can only draw in a single color. You can’t change it, or embed html-ish color codes, to dynamically change the text color. You’ll have to split your text into multiple chunks, each drawn with a single color.

    This means you’ll have to calculate where each string chunk starts/stops using imagettfbbox() and adjust your coordinates in imagetttftext() accordingly.

    comment followup:

    Ok, so individual tag contents, with links being different colors. First step will be to pre-process the string and split it up along link boundaries, so you end up with a series of “text / link / text / link / text” chunks. After that, it’s just a loop:

    $start_x = 5;
    $start_y = 20; // initial x/y coords of text
    $fontsize = 14;
    $font = 'font.ttf';
    $angle = 0;
    
    $black = imagecolorallocate($im, 0, 0, 0);
    $linkcolor = imagecolorallocate($im, ?, ? ,?);
    
    foreach ($string_chunks as $chunk) {
       // get coordinates of bounding box containing text
       $coords = imagegettfbbox($fontsize, $angle, $font, $chunk);
    
       $end_x = $coords[4]; // as per imagetttfbbox() doc page
       $end_y = $coords[5]; // x,y coords of top right corner of bounding box
    
       // figure out which color to draw in
       $color_to_draw = is_link($chunk) ? $linkcolor : $black; 
    
       // draw the text chunk
       imagettftext($im, $fontsize, $angle, $start_x, $start_y, $color_to_draw, $font, $chunk);
    
       // adjust starting coordinates to the END of the just-drawn text
       $start_x += $end_x;
       $start_y += $end_y;
    }
    

    You might need to adjust the coordinates as you go, if there isn’t enough space between
    each chunk of text, or put a space into the string before you get its bounding box.

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

Sidebar

Related Questions

I'm basically taking fileA.xml, grabbing nodes from totally distinct parts of the file, and
Taking over some code from my predecessor and I found a query that uses
Taking advice from this post , I purchased a copy of 'The C Programming
I've been taking a look at some different products for .NET which propose to
I need to generate a number of XML documents from Java objects. The objects
The JAXB documentation is like a text-book, and I simply don't have to time
I am taking an XML file and reading it into various strings, before writing
We have XML file like below... <?xml version='1.0'?> <T0020 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.safersys.org/namespaces/T0020V1 T0020V1.xsd xmlns=http://www.safersys.org/namespaces/T0020V1> <IRP_ACCOUNT>
I want to display data loaded from a webservice but the webservice is taking
Taking shs's question a step further... Why isn't all government sponsored software open source?

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.