imageloadfont

(PHP 4, PHP 5)

imageloadfontЗагрузка шрифта

Описание

int imageloadfont ( string $file )

imageloadfont() загружает определенный пользователем шрифт и возвращает его идентификатор.

Список параметров

file

Формат файла шрифта двоичный и зависит от архитектуры системы. Это означает необходимость генерировать файл шрифта на том же процессоре, на котором работает PHP.

Формат файла шрифта
позиция байта тип данных C описание
байты 0-3 int количество символов в шрифте
байты 4-7 int значение первого символа в шрифте (часто 32 - пробел)
байты 8-11 int ширина пиксела каждого символа
байты 12-15 int высота пиксела каждого символа
байты 16- char массив с данными символов, один байт на пиксел в каждом символе. Для всех кол-во*высота*ширина байт.

Возвращаемые значения

Идентификатор шрифта, который всегда больше 5 для предотвращения конфликтов со встроенными шрифтами, либо FALSE в случае ошибки.

Примеры

Пример #1 Пример использования imageloadfont()

<?php
// Создание нового изображения
$im imagecreatetruecolor(5020);
$black imagecolorallocate($im000);
$white imagecolorallocate($im255255255);

// Белый фон
imagefilledrectangle($im004919$white);

// Загрузка gd шрифта и надпись 'Привет'
$font imageloadfont('./04b.gdf');
imagestring($im$font00'Привет'$black);

// Вывод изображения
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

Смотрите также

Коментарии

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/
2000-08-23 10:23:55
http://php5.kiev.ua/manual/ru/function.imageloadfont.html
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(15060);           
     
imagecolorallocate($imagerand(0100), rand(100150), rand(150250));
     
$fonts scandir($fonts_dir);
     
     
$max count($fonts) - 2;
     
     
$width 10;
     for (
$i 0$i <= strlen($code); $i++)
     {     
         
$textcolor imagecolorallocate($image255255255);
         
$rand rand(2$max);
         
$font imageloadfont($fonts_dir."/".$fonts[$rand]);
         
         
$fh imagefontheight($font);
         
$fw imagefontwidth($font);

         
imagechar($image$font$widthrand(1050 $fh), $code[$i], $textcolor);     
         
$width $width $fw;
       
     }
             
     
imagejpeg($image$location."/".md5($code).".jpg"100);
     
imagedestroy($image);       
   
     return 
$code;
     
}

?>
2005-07-02 08:01:56
http://php5.kiev.ua/manual/ru/function.imageloadfont.html
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.
2005-08-15 13:28:47
http://php5.kiev.ua/manual/ru/function.imageloadfont.html
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.
2005-08-28 21:37:30
http://php5.kiev.ua/manual/ru/function.imageloadfont.html

    Поддержать сайт на родительском проекте КГБ