imagechar

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

imagecharDraw a character horizontally

Опис

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

imagechar() draws the first character of char in the image identified by image with its upper-left at x,y (top left is 0, 0) with the color color.

Параметри

image

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

font

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

x

x-coordinate of the start.

y

y-coordinate of the start.

char

The character to draw.

color

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

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

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

Журнал змін

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

Приклади

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

<?php

$im
= imagecreate(100, 100);

$string = 'PHP';

$bg = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 0, 0, 0);

// prints a black "P" in the top left corner
imagechar($im, 1, 0, 0, $string, $black);

header('Content-type: image/png');
imagepng($im);

?>

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

Output of example : imagechar()

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