I have a problem to put text into a image.
I have all letters in images on my folder named tekst
.
Lets say I use $userinfo->name
to get the user name and in this case the user is named zippo
Then I want the users name to return following HTML output:
<img src="tekst/z.png"><img src="tekst/i.png"><img src="tekst/p.png"><img src="tekst/p.png"><img src="tekst/o.png">
How can I do it with PHP to change each letter in the name to <img src="tekst/?.png>
.
You can use this:
<?php
$name = "zippo";
for ($i = 0; $i < strlen($name); $i++) {
echo '<img src="tekst/' . $name[$i] . '.png">';
}
?>
Use str_split()
function on your string and loop over result array as follows:
$letters = str_split($string);
foreach ($letters as $letter) {
echo '<img src="tekst/' . $letter . '.png" />';
}
First you have to create a php file to convert your text to image :
<?php
/* image.php */
// Receive data
$char = $_GET['char'];
if(!empty($char)){
// This will get the first character from $char
$char = $char;
// Create a 100*30 image
$im = imagecreate(100, 30);
// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);
// Write the string at the top left
imagestring($im, 5, 0, 0, $char, $textcolor);
// Output the image
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
}
?>
Image String http://php.net/manual/en/function.imagestring.php
Then split its name into chars
<?php
$string = 'abcdefgh'; // For example
$chars = str_split($string);
foreach ($chars as $char) {
echo '<img src="tekst/image.php?char='.$char.'"/>';
}
?>
str_split http://php.net/manual/en/function.str-split.php
GOOD LUCK
try this one
$letters = str_split($string);
foreach ($letters as $letter) {
echo '<img src=".../tekst/' . $letter . '.png" />';
}