我通过将上述脚本与我已经存在的脚本合并以生成图像来解决了这个问题。
/* Get image info */
if(!isset($_POST['width']) && !isset($_POST['height']))
{
$width = '200';
$height = '100';
}
else
{
$width = $_POST['width'] ;
$height = $_POST['height'];
}
$Image = imagecreatetruecolor($width,$height) ;
$sx = imagesx($Image) ;
$sy = imagesy($Image) ;
/*Check if RGB values have been set*/
if(!isset($_POST['r'])) { $R = 255; } else { $R = $_POST['r']; }
if(!isset($_POST['g'])) { $G = 255; } else { $G = $_POST['g']; }
if(!isset($_POST['b'])) { $B = 255; } else { $B = str_replace(")" , "" , $_POST['b']); }
/*Check if the text value is set */
if(!isset($_POST['text'])) {$Text = "Uw tekst hier";}
else if($_POST['text'] == '') {$Text = "Uw tekst hier";}
else {$Text = $_POST['text'];}
/*Check if the font is set */
if(!isset($_POST['font'])) {$Font="./Fonts/arial.ttf" ;}
else{$Font= "./fonts/".$_POST['font'].".ttf";}
$FontColor = ImageColorAllocate ($Image,$R,$G,$B) ; //TextColor
$FontShadow = ImageColorAllocate ($Image,0,0,0) ; //BackGroundColor
$Rotation = 0 ;
/* Iterate to get the size up */
$FontSize=1 ;
do
{
$FontSize *= 1.1 ;
$Box = @ImageTTFBBox($FontSize,0,$Font,$Text);
$TextWidth = abs($Box[2] - $Box[6]) ;
$TextHeight = abs($Box[3] - $Box[7]) ;
}
while ($TextWidth < $sx*0.94) ;
/* Awkward maths to get the origin of the text in the right place */
$x = $sx/2 - cos(deg2rad($Rotation))*$TextWidth/2;
$y = $sy/2 + sin(deg2rad($Rotation))*$TextWidth/2 + cos(deg2rad($Rotation))*$TextHeight/2 ;
imagefilledrectangle($Image, 0, 0, $sx , $sy , $FontShadow);
ImageTTFText ($Image,$FontSize,$Rotation,-$Box[6] ,-$Box[7],$FontColor,$Font,$Text);
if(isset($_POST['resize']) && $_POST['resize'] == 1)
{
$nw = 400;
$nh = 200;
$src_img = $Image;
$dst_img = imagecreatetruecolor($nw,$nh);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $nw, $nh, $sx, $sy);//resizing the image
imagepng($dst_img, "hidden.png");
imagedestroy($src_img);
imagedestroy($dst_img);
}
else
{
//header('Content-type: image/png');
Imagepng($Image, "hidden.png") ;
}