I want to place text generated dynamically from a sql select, on an image created with GD library. I'm using this to create the image and place some text on it, but I want to place the variable $users with the sql select data into the image:
$query = "SELECT id, name FROM users WHERE .... ORDER BY id DESC";
while ($line = mysql_fetch_assoc($query)) {
$users .= "<img src='https://www.example.com/" . $line['id'] . "/photo'/> " . $line['name'] . "<br />";
}
function create_image(){
$im = @imagecreate(550, 600)or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 255, 255, 0); // yellow
$red = imagecolorallocate($im, 255, 0, 0); // red
imagestring($im, 1, 5, 10, $users);
imagestring($im, 2, 5, 50, "Text 2", $red);
imagepng($im,"image.png");
imagedestroy($im);
}
create_image();
print "<img src=image.png?".date("U").">";
The text in the $user variable not appear, how can I do this?
Thanks