-
-
Save av-jok/5c50e6dfb9458cde939d5da11449305d to your computer and use it in GitHub Desktop.
Генерация изображения с заданным текстом
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
define('MODX_API_MODE', true); | |
require_once dirname(dirname(__FILE__)) . '/core/config/config.inc.php'; | |
require_once MODX_BASE_PATH . 'index.php'; | |
if (empty($_GET['text'])) { | |
die('введите текст'); | |
} | |
$opts = [ | |
'background' => MODX_ASSETS_PATH . 'img/background.jpg', | |
'font' => MODX_BASE_PATH . 'img/arial.ttf', | |
'save' => MODX_ASSETS_PATH . 'img/g/', | |
'size' => 30, | |
'top' => 200, | |
'left' => 200, | |
'text' => $_GET['text'] | |
]; | |
$path = $opts['save'] . sha1($opts['text']) . '.jpg'; | |
if (!file_exists($path)) { | |
$img = imagecreatefromjpeg($opts['background']); | |
$color = imagecolorallocate($img, 250, 0, 0); | |
/* выводим текст на изображение */ | |
imagettftext( | |
$img, | |
$opts['size'], | |
0, | |
$opts['left'], | |
$opts['top'], | |
$color, | |
$opts['font'], | |
$opts['text'] | |
); | |
imagejpeg($img, $path, 100); | |
imagedestroy($img); | |
} | |
echo '<img src="' . str_replace(MODX_BASE_PATH, MODX_BASE_URL, $path) . '">'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment