Voting

: one plus three?
(Example: nine)

The Note You're Voting On

jwe
18 years ago
Quick tip for anyone who is receiving text like in the example in this page (ie: through $_GET['text'] or something similar) and needs to format the text into multiple lines. The trick is finding the spaces...

<?php
$text
= $_GET['text'];
// for a maximum of 38 characters on a line...
while(strlen($text) > 38) {
$startPoint = 37;
// find a space to break the line on
while(substr($text, $startPoint, 1) != " ") {
$startPoint--;
}
$line[] = trim(substr($text, 0, $startPoint));
$text = substr($text, $startPoint);
}
$line[] = trim($text);
?>

The result is an array called $line that contains all the lines of text you need to output in order.

The only tasks left are to determine the correct height of the image based on the font size you want to use. Don't forget to leave some padding space for punctuation and descenders between lines (commas, g, q, p, y, etc).

imagettftext is unbelievably useful when you need to create header images using non-standard fonts. Amazing. Huge thanks to the devs.

--Julian

<< Back to user notes page

To Top