|
#1
|
|||
|
|||
|
ich möchte mehrer Zeilen Text mit Hilfe der GDlib in ein PNG schreiben. Die einzelnen Zeilen sind in einem Array ($text[]) gespeicht. Das Array durchlaufe ich mit einer FOR-Schleife und ermittle mit Hilfe der imagettftext - Funktion die Texthöhe. Die geht auch hervorragend, solange man die Schriftgröße nicht verändert! Wenn man die Schriftgröße ändert, überlappen die Buchstaben teilweise. Kennt jemand dieses Problem oder hatte jemand schon das gleiche Problem und hat ne Lösung? Hier ein Codeauszug: PHP Quellcode:
$anzahl_zeilen=count($text);
$height_text_gesammt=0; for ($t=0;$t<$anzahl_zeilen;$t++){ $box1 = imagettftext($im2, $schriftgroesse[$t], 0, 0, 0, $schwarz, "schriften/".$font[$t]."".$font_style[$t].".ttf", $text[$t]); $width_text = ($box1[2] - $box1[0]); /////////////////////////////////////////////////////////////////////////////// $tt=$t-1; /////////////////////////////////////////////////////////////////////////////// //ALIGN ERMITTELN /////////////////////////////////////////////////////////////////////////////// if ($align[$t]=="mittig"){ $x=$bild[breite]-$width_text; $x=$x/2; } if ($align[$t]=="links" or !$align[$t]){ $x=3; } if ($align[$t]=="rechts"){ $x=$bild[breite]-$width_text-3; } /////////////////////////////////////////////////////////////////////////////// $box1 = imagettftext($im2, $schriftgroesse[$t], 0, 0, 0, $schwarz, "schriften/".$font[$t]."".$font_style[$t].".ttf", $text[$t]); $height_text = $box1[1] - $box1[7]; $height_text_gesamt=$height_text_gesamt+$height_text; $y=$height_text_gesamt; $box=imagettftext($im, $schriftgroesse[$t], 0, $x, $y, $schwarz, "schriften/".$font[$t]."".$font_style[$t].".ttf", $text[$t]); $height_text_gesamt=$height_text_gesamt+$zeilenabstand[$t]; }
__________________
Fritz the Cat - Webmaster phpforum.de |
|
#2
|
|||
|
|||
|
Sieht ganz so aus,als wenn man nur die ascent-Maße der Schrift erhält, nicht die descent-Maße (also die unterhalb der baseline)
PHP Quellcode:
<?php
$im = imagecreate(800, 200); $weiß = imagecolorallocate($im, 0,0,0); $schwarz = imagecolorallocate($im, 255,255,255); $rot = imagecolorallocate($im, 255,0,0); $size = 36; $font = 'schriften/arial.ttf'; $text = 'aAfFgGIipPqQxX;'; $bbox = imagettfbbox($size, 0, $font, $text); $height = $bbox[3] - $bbox[7]; $width = $bbox[2] - $bbox[0]; imagettftext($im, $size, 0, 0, $height, $schwarz, $font, $text); imagerectangle($im, 0, 0, $width, $height, $rot); header('Content-type: image/jpeg'); imagejpeg($im); ?> Zitat:
Zitat:
|
|
#3
|
|||
|
|||
|
Hat den keiner noch nen Tipp???
Ich bin am verzweifeln!
__________________
Fritz the Cat - Webmaster phpforum.de |
|
#4
|
|||
|
|||
|
ah, ich habe meinen Fehler gefunden und ich denke, das ist auch der Fehler bei Dir
PHP Quellcode:
<?php
$im = imagecreate(800, 200); $schwarz = imagecolorallocate($im, 0,0,0); $weiß = imagecolorallocate($im, 255,255,255); $rot = imagecolorallocate($im, 255,0,0); $grau = imagecolorallocate($im, 40,40,40); $blau = imagecolorallocate($im, 40,40,255); $size = 36; $font = 'schriften/times.ttf'; $text = 'AgpQ;'; for($i=0; $i <210; $i+=10) imageline($im, 0, $i, 700, $i, $grau); // das ist richtig: $bbox = imagettfbbox($size, 0, $font, $text); $ascent=abs($bbox[5]); $descent=$bbox[1]; $height = $ascent + $descent; $width = $bbox[2]-$bbox[0]; imagettftext($im, $size, 0, 0, $ascent, $weiß, $font, $text); imagerectangle($im, 0, 0, $width, $height, $rot); imageline($im, 0, $ascent, 700, $ascent, $blau); // so war es ungefähr vorher // und so ist es auch bei Dir imagettftext($im, $size, 0, $width+40, $height, $weiß, $font, $text); imagerectangle($im, $width+40, 0, ($width+40)+$width, $height, $rot); header('Content-type: image/jpeg'); imagejpeg($im); ?> Versuch es mal so PHP Quellcode:
<?php
$anzahl_zeilen=count($text); $height_text_gesamt=0; for ($t=0;$t<$anzahl_zeilen;$t++) { $fontfile = 'schriften/'.$font[$t].$font_style[$t].'.ttf'; $box1 = imagettfbbox($schriftgroesse[$t], 0, $fontfile, $text[$t]); $ascent_text = abs($box1[5]); $descent_text=$box1[1]; $height_text=$ascent_text + $descent_text; $width_text = ($box1[2] - $box1[0]); /** ALIGN ERMITTELN */ if ('mittig'===$align[$t]) { $x=$bild['breite']-$width_text; $x=$x/2; } elseif ('rechts'===$align[$t]) { $x=$bild['breite']-$width_text-3; } else { $x=3; } $y=$height_text_gesamt + $ascent_text; $box=imagettftext($im, $schriftgroesse[$t], 0, $x, $y, $schwarz, $fontfile, $text[$t]); $height_text_gesamt=$height_text_gesamt+$height_text+$zeilenabstand[$t]; } ?> |
|
#5
|
|||
|
|||
|
Du bist der Held des Tages!!!!!!!
Es geht....!!!! Ich saß jetzt wirklich fast 3 ganze Tage an dem Problem, und kam einfach nicht drauf!!! DANKE
__________________
Fritz the Cat - Webmaster phpforum.de |
| Lesezeichen |
| Themen-Optionen | |
| Ansicht | |
|
|
|
|
||||
| Thema | Autor | Forum | Antworten | Letzter Beitrag |
| Zeilenabstand bei Firefox und IE | raso | Sonstiges | 11 | 19.09.2005 20:06 |
| Grundlagenfrage: Zeilenabstand nach enter | Railroad24 | HTML | 8 | 04.11.2004 13:05 |
| Zeilenabstand.. | NicolaiBassDH | HTML | 3 | 24.11.2003 17:03 |