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.
Share
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 inimagetttftext()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:
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.