Einzelnen Beitrag anzeigen

Nuclear-Ping
(Gast)

n/a Beiträge
 
#5

Re: [PHP] Schriften bändigen

  Alt 13. Jul 2007, 19:08
Die Positionierung in den Buttons funktioniert jetzt recht gut (siehe Link im ersten Beitrag).

Allerdings folgt auch gleich das zweite Problem: Wenn man auf die Buttons klickt, werden oben in der Vorschau die Buttons dargestellt. Mit 'ner Formel, die die Zeichen einfach mittig zentriert funktioniert das generell gut. Allerdings werden Buchstaben wie p, q, b, d halt anders dargestellt als a, c, e, o, ...

Jemand eine Idee, wie man das berechnen kann? Werde aus den Ergebnissen von ImageTTFBBox nicht schlau ...

Code:
<?
   // *****************************
   // File: charimage.php
   // Erstellt ein Bild eines Schriftzeichens mit den
   // Parametern aus der Übergabe
   // Aufruf: ./charimage.php?font=tahoma.ttf&char=112&height=34
   // *****************************

   require ("config.php");
   require ("functions.php");

   // [url]http://de3.php.net/manual/en/function.imagettfbbox.php#76333[/url]
   function better_imagettfbbox($size, $angle, $font, $text) {
        $dummy = imagecreate(1, 1);
        $black = imagecolorallocate($dummy, 0, 0, 0);
        $bbox = imagettftext($dummy, $size, $angle, 0, 0, $black, $font, $text);
        imagedestroy($dummy);
        return $bbox;
   }

   $Char = chr ($_REQUEST["char"]);
   $Font = $_REQUEST["font"];
   $FontHeight = $_REQUEST["height"];
   $Size = 20;

   $Box = better_imagettfbbox ($Size, 0, $FontPath . $Font, $Char);

   $yvar1 = $Box[5] > $Box[7] ? $Box[5] : $Box[7];
   $yvar2 = $Box[1] < $Box[3] ? $Box[1] : $Box[3];

   // Höhe und Breite des Schriftzeichens berechnen
   $szheight = abs($yvar1 - $yvar2);
   $szwidth = abs($Box[4] - $Box[0]);
   $FontWidth = $szwidth;
//   $FontHeight = $szheight;

//         echo "<pre>"; print_r ($Box); echo "</pre>";

   $im = ImageCreate ($FontWidth, $FontHeight);
   $back_color = ImageColorAllocate ($im, $ShadowColor[0], $ShadowColor[1], $ShadowColor[2]);
//   $back_color = ImageColorAllocate ($im, $BackColor[0], $BackColor[1], $BackColor[2]);
   $text_color = ImageColorAllocate ($im, $TextColor[0], $TextColor[1], $TextColor[2]);

   // Versuch, einen Offset zu bestimmen
   $belowBasepoint = max (0, abs ($Box[1]));
//   echo (int)$belowBasepoint;
   if ($belowBasepoint != 0) {
      $YOffset = -$Box[1];
      $XOffset = -$Box[0];
   } else {
      $YOffset = -$Box[1] - ($FontHeight - $szheight);
      $XOffset = -$Box[0];
          }

   ImageTTFText ($im, $Size, 0, $XOffset, $FontHeight + $YOffset, $text_color, $FontPath . $Font, $Char);

   Header("Content-type: image/png");
   ImagePNG ($im);
   ImageDestroy ($im);
?>
  Mit Zitat antworten Zitat