Ik heb een script om afbeeldingen te genereren:
<?php
function write_multiline_text($image, $font_size, $color, $font, $text, $start_x, $start_y, $max_width) {
//split the string
//build new string word for word
//check everytime you add a word if string still fits
//otherwise, remove last word, post current string and start fresh on a new line
$words = explode(" ", $text);
$string = "";
$tmp_string = "";
for($i = 0; $i < count($words); $i++) {
$tmp_string .= $words[$i]." ";
//check size of string
$dim = imagettfbbox($font_size, 0, $font, $tmp_string);
if($dim[4] < ($max_width - $start_x)) {
$string = $tmp_string;
$curr_width = $dim[4];
} else {
$i--;
$tmp_string = "";
$start_xx = $start_x + round(($max_width - $curr_width - $start_x) / 2);
imagettftext($image, $font_size, 0, $start_xx, $start_y, $color, $font, $string);
$string = "";
$start_y += abs($dim[5]) * 2;
$curr_width = 0;
}
}
$start_xx = $start_x + round(($max_width - $dim[4] - $start_x) / 2);
imagettftext($image, $font_size, 0, $start_xx, $start_y, $color, $font, $string);
}
// Create a 300x300 image
$im = imagecreatetruecolor(300, 300);
$im = imagecreatefrompng('background.png');
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Set the background to be white
imagefilledrectangle($im, 1, 1, 298, 298, $white);
// Path to our font file
$font = 'c:/windows/fonts/arial.ttf';
$text = "This is a very ";
$text .= "long long long long long long long long long long long long long long long long ";
$text .= "long long long long long long long long long long long long long long long long ";
$text .= "line of text";
write_multiline_text($im, 12, $black, $font, $text, 10, 22, 298);
// Output to browser
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
Er wordt een achtergrond ingeladen, maar nu wil ik ook graag een statische Google Maps-afbeelding (png). Inladen (bijvoorbeeld staticmap.png op de server). Nu is mijn vraag, hoe moet ik dat doen via write_multiline_text (de functie die hierboven is gemaakt)?
Ik heb al gegoogled, maar ik kom er niet uit. Kan iemand mij helpen misschien?