Working under the assumption that the only 'architecture dependant' part of the font files is endianness, I wrote a quick and dirty Python script to convert between the two. It has only been tested on a single font on a single machine so don't bet your life on it working. All it does is swap the byte order of the first four ints.
#!/usr/bin/env python
f = open("myfont.gdf", "rb");
d = open("myconvertedfont.gdf", "wb");
for i in xrange(4):
b = [f.read(1) for j in xrange(4)];
b.reverse();
d.write(''.join(b));
d.write(f.read());
I successfully used this script to convert anonymous.gdf, from one of the font links below, into something useable on Mac OS X.
imageloadfont
(PHP 4, PHP 5)
imageloadfont — Charge une nouvelle police
Description
int imageloadfont
( string
$file
)imageloadfont() charge une nouvelle police utilisateur et retourne son identifiant.
Liste de paramètres
-
file -
Le format des polices dépend actuellement du système d'exploitation. Ce qui signifie qu'il vous faut générer des fichiers de polices pour la machine qui fait tourner PHP.
Format de fichier de police Position Type de données C Description Octets 0-3 int Nombre de caractères de la police Octets 4-7 int Valeur du premier caractère de la police (souvent 32 pour espace) Octets 8-11 int Largeur en pixels des caractères Octets 12-15 int Hauteur en pixels des caractères Octets 16- char Tableau avec les données des caractères, un octet par pixel pour chaque caractère, avec un total de (nombre de caractères * largeur * hauteur) octets.
Valeurs de retour
L'identifiant de la police qui sera toujours supérieur à 5 afin d'éviter
les conflits avec les polices internes ou FALSE si une erreur survient.
Exemples
Exemple #1 Exemple avec imageloadfont()
<?php
// Création d'une nouvelle image
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
// Définit l'arrière-plan en blanc
imagefilledrectangle($im, 0, 0, 49, 19, $white);
// Charge la police GD et écrit 'Bonjour !'
$font = imageloadfont('./04b.gdf');
imagestring($im, $font, 0, 0, 'Bonjour !', $black);
// Affichage sur le navigateur
header('Content-type: image/png');
imagepng($im);
imagedestroy($im);
?>
Voir aussi
- imagefontwidth() - Retourne la largeur de la police
- imagefontheight() - Retourne la hauteur de la police
siker at norwinter dot com ¶
7 years ago
alex at bestgames dot ro ¶
7 years ago
Confirmation code generation for preventing automated registrations on a website.
Function arguments are:
$code - the code that you shall random generate
$location - relative location of the image that shall be generated
$fonts_dir - relative location for the GDF fonts directory
This function will create an image with the code given by you and will save it in the directory specified with the name formed by MD5 hash of the code.
You may insert as many font types in the fonts directory as you wish, with random names.
<?php
function generate_image($code, $location, $fonts_dir)
{
$image = imagecreate(150, 60);
imagecolorallocate($image, rand(0, 100), rand(100, 150), rand(150, 250));
$fonts = scandir($fonts_dir);
$max = count($fonts) - 2;
$width = 10;
for ($i = 0; $i <= strlen($code); $i++)
{
$textcolor = imagecolorallocate($image, 255, 255, 255);
$rand = rand(2, $max);
$font = imageloadfont($fonts_dir."/".$fonts[$rand]);
$fh = imagefontheight($font);
$fw = imagefontwidth($font);
imagechar($image, $font, $width, rand(10, 50 - $fh), $code[$i], $textcolor);
$width = $width + $fw;
}
imagejpeg($image, $location."/".md5($code).".jpg", 100);
imagedestroy($image);
return $code;
}
?>
matthew at exanimo dot com ¶
7 years ago
Remember - GD fonts aren't antialiased. If you're planning on using a pre-existing (TrueType) font, you may want to consider using imagettftext() instead of phillip's function.
puremango dot co dot uk at gmail dot com ¶
8 years ago
I've written an online tool in PHP that allows you to create GD fonts from PNG images.
much usefulness for custom font creation, I feel.
see the tool@
http://puremango.co.uk/cm_fontmaker_114.php
(source available online)
null at phpmix dot com ¶
8 years ago
Sometime ago I wrote a small tutorial on how to create dynamic signatures using gd_fonts. I also uploaded some gd_fonts...
You can check it out here, if you wish:
http://www.phpmix.com/phpBB2/viewtopic.php?t=328
Hope that helps
widget at oneblacksheep dot com ¶
8 years ago
After noting the gd fonts page from dryes58 above was down I contacted the him and have put the pages up at http://www.widgnet.com/gdf_fonts/ hows about that then =)
angryziber at mail dot com ¶
12 years ago
You all should look at the GD image library site for information on extra fonts, it can be found at http://www.boutell.com/gd/
