Suchen
Inside Forum
Nützliche Links
PHP Jobs
phpforum.de Tipp
 
phpforum.de bei Facebook
 
phpforum.de bei Twitter
 
PHP Test


werbung



Zurück   PHP Forum: phpforum.de > PHP > PHP

PHP Alles rund um PHP

Antwort
 
Themen-Optionen Ansicht
  #1  
Alt 11.11.2003, 00:59
dacat dacat ist offline
Forum-Mitarbeiter
 
Registriert seit: 02.12.2002
Ort: Bammental
Beiträge: 1.507
Standard

Hallo, sitze jetzt schon verdammt lange an folgendem Problem:

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];

}
Bin für jeden Tipp Dankbar!!!
__________________
Fritz the Cat - Webmaster phpforum.de
Mit Zitat antworten
  #2  
Alt 11.11.2003, 07:40
VolkerK VolkerK ist offline
Engagierter Besucher
 
Registriert seit: 01.11.2003
Ort: auuuus Berlin
Beiträge: 3.615
VolkerK eine Nachricht über ICQ schicken
Standard

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);
?>
wie man an diese Werte ran kommt, weiß ich leider nicht

Zitat:
$box1 = imagettftext($im2, $schriftgroesse[$t], 0, 0, 0, $schwarz, "schriften/".$font[$t]."".$font_style[$t].".ttf", $text[$t]);
$width_text = ($box1[2] - $box1[0]);
...
$box1 = imagettftext($im2, $schriftgroesse[$t], 0, 0, 0, $schwarz, "schriften/".$font[$t]."".$font_style[$t].".ttf", $text[$t]);
$height_text = $box1[1] - $box1[7];
Waum liest Du die boundingbox eigentlich zweimal aus? Höhe und Breite ändern sich zwischendurch doch nicht. Und warum mit einem Dummy-Bild? Es gibt doch http://php.net/imagettfbbox
Zitat:
$x=$bild[breite]-$width_text;
sofern breite kein define() ist: http://php.net/language.types.array#...es.array.donts
Mit Zitat antworten
  #3  
Alt 11.11.2003, 11:58
dacat dacat ist offline
Forum-Mitarbeiter
 
Registriert seit: 02.12.2002
Ort: Bammental
Beiträge: 1.507
Standard

Hat den keiner noch nen Tipp???

Ich bin am verzweifeln! (
__________________
Fritz the Cat - Webmaster phpforum.de
Mit Zitat antworten
  #4  
Alt 11.11.2003, 15:08
VolkerK VolkerK ist offline
Engagierter Besucher
 
Registriert seit: 01.11.2003
Ort: auuuus Berlin
Beiträge: 3.615
VolkerK eine Nachricht über ICQ schicken
Standard

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);

?>
$height_text = $box1[1] - $box1[7]; <- das ist zwar richtig, aber die y-Positionierung bei imagettftext geschieht über die baseline (die blaue Linie in meinem Skript).

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];
}
?>
(nur per syntaxcheck getestet)
Mit Zitat antworten
  #5  
Alt 11.11.2003, 15:18
dacat dacat ist offline
Forum-Mitarbeiter
 
Registriert seit: 02.12.2002
Ort: Bammental
Beiträge: 1.507
Standard

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
Mit Zitat antworten


Antwort

Lesezeichen

Themen-Optionen
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.

Gehe zu
Ähnliche Themen
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


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:41 Uhr.


Powered by vBulletin® Version 3.8.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Powered by NuWiki v1.3 RC1 Copyright ©2006-2007, NuHit, LLC