PHP
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

imagepalettecopy> <imageline
Last updated: Fri, 19 Jun 2009

view this page in

imageloadfont

(PHP 4, PHP 5)

imageloadfontCargar una fuente nueva

Descripción

int imageloadfont ( string $archivo )

imageloadfont() carga un bitmap definido por el usuario y devuelve su identificador.

Lista de parámetros

archivo

El formato del archivo de la fuente es binario en la actualidad y dependiente de la arquitectura. Esto quiere decir que usted debería generar los archivos de fuentes en el mismo tipo de CPU que posee la máquina en la que está ejecutando PHP.

Formato del archivo de fuente
posición de byte tipo de datos C descripción
byte 0-3 int número de caracteres en la fuente
byte 4-7 int valor del primer caracter en la fuente (con frecuencia 32, indicando el espacio)
byte 8-11 int ancho de píxel de cada caracter
byte 12-15 int altura de píxel de cada caracter
byte 16- char matriz con datos de caracteres, un byte por píxel en cada caracter, para un total de (n_caracteres*ancho*altura) bytes.

Valores retornados

El identificador de la fuente, el cual es siempre mayor que 5 para evitar conflictos con fuentes definidas internamente, o FALSE en caso de errores.

Ejemplos

Example #1 Uso de imageloadfont

<?php
header
("Content-type: image/png");
$im imagecreatetruecolor(5020);
$negro imagecolorallocate($im000);
$blanco imagecolorallocate($im255255255);
imagefilledrectangle($im004919$blanco);
$fuente imageloadfont("04b.gdf");
imagestring($im$fuente00"Hola"$negro);
imagepng($im);
?>

Ver también



imagepalettecopy> <imageline
Last updated: Fri, 19 Jun 2009
 
add a note add a note User Contributed Notes
imageloadfont
widget at oneblacksheep dot com
21-Nov-2007 11:07
The url for the gdf fonts page has now changed to http://www.devtrolls.com/gdf_fonts/ the old url will redirect for a short while.
dave [at] wedwick.com
08-Jan-2007 02:55
I created a Windows program to convert Windows fonts to PHP fonts.  It shows a preview as well as allows sample text to be entered.

http://www.wedwick.com/wftopf.exe
siker at norwinter dot com
29-Aug-2005 01:37
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.
matthew at exanimo dot com
15-Aug-2005 05:28
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.
alex at bestgames dot ro
02-Jul-2005 12:01
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;
    
}

?>
puremango dot co dot uk at gmail dot com
22-Apr-2005 12:54
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
22-Dec-2004 05:59
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
05-Jun-2004 12:41
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
23-Aug-2000 02:23
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/

imagepalettecopy> <imageline
Last updated: Fri, 19 Jun 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites