Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于文本PHP的动态图像_Php_Gd_Gd2 - Fatal编程技术网

基于文本PHP的动态图像

基于文本PHP的动态图像,php,gd,gd2,Php,Gd,Gd2,我想使用GD生成一个奇特的字体文本图像 我发现: <?php // Settings $sText = 'This is just a test!'.@$_GET['t']; // Text of heading $sFont = 'Bryant-Bold.ttf'; // Default font for headings $sMain = @$_GET['c'] ? $_GET['c'] : 0xF2AB27; // Get a font or default it // Calcu

我想使用GD生成一个奇特的字体文本图像

我发现:

<?php
// Settings
$sText = 'This is just a test!'.@$_GET['t']; // Text of heading
$sFont = 'Bryant-Bold.ttf'; // Default font for headings
$sMain = @$_GET['c'] ? $_GET['c'] : 0xF2AB27; // Get a font or default it

// Calcuate the width of the image
$arSize = imagettfbbox(24, 0, $sFont, $sText);
$iWidth = abs($arSize[2] - $arSize[0]);
$iHeight = abs($arSize[7] - $arSize[1]);

// Create the image
header("Content-Type: image/png"); // Set the content-type
$hImage = imagecreatetruecolor(200, 24);
ImageFill($hImage, 0, 0, IMG_COLOR_TRANSPARENT);
imagesavealpha($hImage, true);
imagealphablending($hImage, false);
imagettftext($hImage, 20, 0, 0, 24, $sMain, $sFont, $sText); // Draw the text
imagepng($hImage); // Generate the image
imagedestroy($hImage); // Destroy it from the cache
?>

但看起来是这样的:
(切掉部分)

输出图像的固定宽度为200

$hImage = imagecreatetruecolor(200, 24);
您应该动态计算宽度-可能需要使用变量
$hImage

$hImage = imagecreatetruecolor($hImage, 24);