Home   Fonts   Questions   Tips   Forum   Imprint 
The FontShack - free fonts for pc and mac
free fonts for pc and mac  
fontes gratis para la PC y el mac  
Kostenlose Schriften für PC und Mac  
»» A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #



free fonts

:.· Fonts in Webpage as PHP-Code


:.· Thumbnailgeneration

Thumbnails for Truetype fonts can be easily created with a PHP Script. This method is very handy for generateing thumbs for large font collections. (The thumbnails of The FontShack are created exactly the same way)

First, you have to read the directory in which the font reside:
$fontdir= "./fonts/";
$dir = opendir($fontdir);
while(false !== ($file = readdir($dir))) {
   if (eregi("\.". "ttf" ."$", $file)) {
         //do something: add to array or as option into a select-list.
      }
   }
Generating the thumbnails is done with the following snippet:
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";
   $name_file = $f; 
   $fontsource = "$absolutpfad$bildpfad$name_file";
   $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, "Textzeile1");
   ImageTTFText($img, 20, 0, 5, 75, $grey, $fontsource, "Textzeile2");
   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); 
   }
Important here is the command ImageTTFText() which writes the text in the selected font into a bitmap. Imagepng() saves the bitmap to disk. Like we stated before you shouldn't generate JPG file, because of the lack of font clarity and the occurance of artefacts on the serifs.

Free Fonts
Recommendation
Did you know?
After five years we´ve changed to an up-to-date and easier to use site-layout.
Newsletter Sign up to be the first to know about updates at the FontShack:
Name:
E-Mail:
 
Donate to support The FontShack
Deutsch   English   Espagnol, no disponible
Search for fonts:
  © 2001-2008 by Fontshack.com. All Rights reserved. Unauthorized copying not permitted.