imagestring

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

imagestringDraw a string horizontally

Опис

imagestring(
    GdImage $image,
    GdFont|int $font,
    int $x,
    int $y,
    string $string,
    int $color
): bool

Draws a string at the given coordinates.

Параметри

image

Об'єкт GdImage, що повертається однією з функцій створення зображення, такою як imagecreatetruecolor().

font

Може бути 1, 2, 3, 4, 5 для вбудованих шрифтів в кодуванні latin2 (де більші числа відповідають більшим шрифтам) або примірником класу GdFont, що повертається функцією imageloadfont().

x

x-coordinate of the upper left corner.

y

y-coordinate of the upper left corner.

string

The string to be written.

color

Ідентифікатор кольору, створений за допомогою imagecolorallocate().

Значення, що повертаються

Повертає true у разі успіху або false в разі помилки.

Журнал змін

Версія Опис
8.1.0 Параметром font тепер може бути як і примірник GdFont, так і int. Раніше допускався тільки int.
8.0.0 Тепер image має бути примірником GdImage. Раніше очікувався gd-resource.

Приклади

Приклад #1 imagestring() example

<?php
// Create a 100*30 image
$im = imagecreate(100, 30);

// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write the string at the top left
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);

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

imagepng($im);
?>

Поданий вище приклад виведе щось схоже на:

Output of example : imagestring()

Прогляньте також