Delicious Bookmark this on Delicious Share on Facebook SlashdotSlashdot It! Digg! Digg



PHP : Function Reference : Image Functions : imageloadfont

imageloadfont

Load a new font (PHP 4, PHP 5)
int imageloadfont ( string file )

Example 1017. Using imageloadfont

<?php
header
("Content-type: image/png");
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);
imagefilledrectangle($im, 0, 0, 49, 19, $white);
$font = imageloadfont("04b.gdf");
imagestring($im, $font, 0, 0, "Hello", $black);
imagepng($im);
?>

Code Examples / Notes » imageloadfont

angryziber

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/

siker

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.


null

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


matthew

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

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)


dave

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


alex

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;
   
}
?>


widget

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 =)

Change Language


Follow Navioo On Twitter
gd_info
getimagesize
image_type_to_extension
image_type_to_mime_type
image2wbmp
imagealphablending
imageantialias
imagearc
imagechar
imagecharup
imagecolorallocate
imagecolorallocatealpha
imagecolorat
imagecolorclosest
imagecolorclosestalpha
imagecolorclosesthwb
imagecolordeallocate
imagecolorexact
imagecolorexactalpha
imagecolormatch
imagecolorresolve
imagecolorresolvealpha
imagecolorset
imagecolorsforindex
imagecolorstotal
imagecolortransparent
imageconvolution
imagecopy
imagecopymerge
imagecopymergegray
imagecopyresampled
imagecopyresized
imagecreate
imagecreatefromgd2
imagecreatefromgd2part
imagecreatefromgd
imagecreatefromgif
imagecreatefromjpeg
imagecreatefrompng
imagecreatefromstring
imagecreatefromwbmp
imagecreatefromxbm
imagecreatefromxpm
imagecreatetruecolor
imagedashedline
imagedestroy
imageellipse
imagefill
imagefilledarc
imagefilledellipse
imagefilledpolygon
imagefilledrectangle
imagefilltoborder
imagefilter
imagefontheight
imagefontwidth
imageftbbox
imagefttext
imagegammacorrect
imagegd2
imagegd
imagegif
imagegrabscreen
imagegrabwindow
imageinterlace
imageistruecolor
imagejpeg
imagelayereffect
imageline
imageloadfont
imagepalettecopy
imagepng
imagepolygon
imagepsbbox
imagepsencodefont
imagepsextendfont
imagepsfreefont
imagepsloadfont
imagepsslantfont
imagepstext
imagerectangle
imagerotate
imagesavealpha
imagesetbrush
imagesetpixel
imagesetstyle
imagesetthickness
imagesettile
imagestring
imagestringup
imagesx
imagesy
imagetruecolortopalette
imagettfbbox
imagettftext
imagetypes
imagewbmp
imagexbm
iptcembed
iptcparse
jpeg2wbmp
png2wbmp
eXTReMe Tracker