PHP.mk документација

imageloadfont

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.imageloadfont.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.imageloadfont.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
imageloadfont

Референца за `function.imageloadfont.php` со подобрена типографија и навигација.

function.imageloadfont.php

imageloadfont

(PHP 4, PHP 5, PHP 7, PHP 8)

imageloadfontВчитај нов фонт

= NULL

imageloadfont(string $filename): GdFont|false

imageloadfont() вчита една кориснички дефинирана растерска слика и враќа нејзин идентификатор.

Параметри

filename

Форматот на фонт датотеката моментално е бинарен и зависен од архитектурата. Ова значи дека треба да ги генерирате фонт датотеките на ист тип на процесор како машината на која го стартувате PHP.

Формат на фонт датотека
позиција на бајт C тип на податок description
бајт 0-3 int број на знаци во фонтот
бајт 4-7 int вредност на првиот знак во фонтот (често 32 за празно место)
бајт 8-11 int ширина во пиксели на секој знак
бајт 12-15 int висина во пиксели на секој знак
бајт 16- char низа со податоци за знаци, еден бајт по пиксел во секој знак, за вкупно (nchars*width*height) бајти.

Вратени вредности

Враќа GdFont инстанца, или false при неуспех.

Дневник на промени

Верзија = NULL
8.1.0 Враќа GdFont инстанца сега; претходно, а int .

Примери

Пример #1 imageloadfont() пример за употреба

<?php
// Create a new image instance
$im = imagecreatetruecolor(50, 20);
$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

// Make the background white
imagefilledrectangle($im, 0, 0, 49, 19, $white);

// Load the gd font and write 'Hello'
$font = imageloadfont('./04b.gdf');
imagestring($im, $font, 0, 0, 'Hello', $black);

// Output to browser
header('Content-type: image/png');

imagepng($im);
?>

Види Исто така

Белешки од корисници 3 белешки

siker на norwinter точка com
20 години пред
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.
alex na bestgames dot ro
20 години пред
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 na exanimo dot com
20 години пред
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.
Навигација

Прелистувај сродни теми и функции.

На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.