ibi icon

ttf2png (html/php)

ibi | PRO | 05/20/14 09:00:46 AM UTC | 0 ⭐ | 599 👁️ | Never ⏰ | []
PHP |

2.87 KB

|

None

|

0 👍

/

0 👎

<body>
<b>TTF2PNG</b> - create png from ttf
<a href="<?php echo $PHP_SELF?>">:: home ::</a><br>
<form name="ttf2png">
 
filename:<select name="f" onChange="javascript:UpdInp()">
<option>---Select
<?php
 
$fontdir= "./fonts/";
 
$dir = opendir($fontdir);
while(false !== ($file = readdir($dir)))
   {
   if (eregi("\.". "ttf" ."$", $file)) 
      {
      echo "<option>".$file; 
      }
   }
?>
</select>
<br>
fontname:<input type=text name="n">
<br>
<input type=submit>
</form>
 
<?php
// create the thumbnail. :)
if($n && $f) {
   echo "creating png of $n out of $f";
   create_png($f,$n);
   }
 
function create_png($f,$n) {
        global $fontdir;
        $bildpfad = $fontdir;
        $absolutpfad = getcwd(); //absolute Pfadangabe auslesen      
        $picpfad = "$absolutpfad$bildpfad";
        $file_body = str_replace(" ", "_", $n);
        $thumb_file = $file_body.".png";
        $thumb_file_big = $file_body."_b.png";
        $name_file = $f; 
        $fontsource = "$absolutpfad$bildpfad$name_file";
        echo "<br>$fontsource<br>";
        $breite = 250;
        $hoehe = 80;
        $img = imagecreate ($breite, $hoehe);
        $black = ImageColorAllocate ($img, 0, 0, 0);
        $white = ImageColorAllocate ($img, 255, 255, 255);
        $grey = ImageColorAllocate ($img, 192, 192, 192);
        $bordercol = ImageColorAllocate ($img, 239, 237, 222);
        imagefilledrectangle($img, 0, 0, $breite, $hoehe, $white);
        ImageTTFText($img, 20, 0, 5, 25, $black, $fontsource, $n);
        ImageTTFText($img, 20, 0, 5, 50, $grey, $fontsource, "abcdefghijklmnopqrstuvwxyz");
        ImageTTFText($img, 20, 0, 5, 75, $grey, $fontsource, "ABCDEFGHIJK - 0123456789");
        imagerectangle($img, 1, 1, $breite-1, $hoehe-1, $bordercol);
        imagefilledrectangle($img, $breite-4, 2, $breite-2, $hoehe-2, $white);
        imagefilledrectangle($img, 2, $hoehe-4, $breite-2, $hoehe-2, $white);
        Imagepng($img,"$picpfad$thumb_file",80); 
 
        $img = imagecreate ($breite, $hoehe);
        $black = ImageColorAllocate ($img, 0, 0, 0);
        $white = ImageColorAllocate ($img, 255, 255, 255);
        $grey = ImageColorAllocate ($img, 192, 192, 192);
        $bordercol = ImageColorAllocate ($img, 239, 237, 222);
        imagefilledrectangle($img, 0, 0, $breite, $hoehe, $white);
        ImageTTFText($img, 50, 0, 5, 70, $black, $fontsource, $n." 1234567890");
        imagerectangle($img, 1, 1, $breite-1, $hoehe-1, $bordercol);
        imagefilledrectangle($img, $breite-4, 2, $breite-2, $hoehe-2, $white);
        imagefilledrectangle($img, 2, $hoehe-4, $breite-2, $hoehe-2, $white);
        Imagepng($img,"$picpfad$thumb_file_big",80); 
        ImageDestroy ($img); 
   }
 
?>
<br><img src="/fonts/<?php echo str_replace(" ", "_", $n)?>.png">
<br><img src="/fonts/<?php echo str_replace(" ", "_", $n)?>_b.png">
</div>
</body>

Comments