Files
php_8/gd/button.php
2022-06-09 13:51:30 +03:00

19 lines
1.1 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// Получаем строку, которую нам передали в параметрах
$string = $_SERVER['QUERY_STRING'] ?? 'Hello, world!';
// Загружаем рисунок фона с диска
$im = imageCreateFromGif('button.gif');
// Создаем в палитре новый цвет - черный
$color = imageColorAllocate($im, 0, 0, 0);
// Вычисляем размеры текста, который будет выведен
$px = (imageSX($im) - 6.5 * strlen($string)) / 2;
// Выводим строку поверх того, что было в загруженном изображении
imageString($im, 3, intval($px), 1, $string, $color);
// Сообщаем о том, что далее следует рисунок PNG
header('Content-type: image/png');
// Теперь - самое главное: отправляем данные картинки в
// стандартный выходной поток, т. е. в браузер
imagePng($im);
// В конце освобождаем память, занятую картинкой
imageDestroy($im);