Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.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中创建不同文本格式的gif图像?_Php - Fatal编程技术网

如何使用背景图像在php中创建不同文本格式的gif图像?

如何使用背景图像在php中创建不同文本格式的gif图像?,php,Php,这是否可以创建具有各种文本字体、样式、格式和对齐方式的gif图像,并在php中具有背景图像 例如,我有一个背景图像,如 我想在背景图像上插入的图像是 输出的gif图像应该如下所示 我试过这个密码 <?php // Create a new image instance $im = imagecreatetruecolor(300, 250); $img = imagecreatefrompng('back.png'); // Make the background white imag

这是否可以创建具有各种文本字体、样式、格式和对齐方式的gif图像,并在php中具有背景图像

例如,我有一个背景图像,如

我想在背景图像上插入的图像是

输出的gif图像应该如下所示

我试过这个密码

<?php
// Create a new image instance
$im = imagecreatetruecolor(300, 250);
$img = imagecreatefrompng('back.png');
// Make the background white
imagefilledrectangle($im, 0, 0, 300, 250, 0xEFEFEF);

// Draw a text string on the image

imagestring($im, 20,20, 40, 'Heading1', 0x000000);
imagecopymerge($img, $im, 0, 0, 0, 0, 300, 250, 70);
// Output the image to browser
header('Content-Type: image/gif');

imagegif($img,'test.gif');
imagedestroy($im);
?>
但不幸的是,它并没有提供所需的输出,我想向背景图像添加更多内容,如我在输出图像中所示

对于此设计:

您可以使用以下代码:

<?php
// Create a new image instance
$img = imagecreatefrompng('back.png');

// Draw a text string on the image
//  imagestring ( resource $image , int $font , int $x , int $y , string $string , int $color )
imagestring($img, 5, 20, 30, 'Heading1', 0x000000);
imagestring($img, 3, 180, 30, 'Heading 2 test desc', 0x000000);

imagestring($img, 3, 20, 80, 'Text info 3', 0xFF0000);   //red
imagestring($img, 1, 180, 80, 'Demonstration text', 0x000000);

imagestring($img, 5, 400, 170, 'Price here', 0xFF0000);   //red

$im = imagecreatefrompng('plane.png'); //load pic 2
imagecopymerge($img, $im, 0, 130, 0, 0, 165, 71, 70);
imagedestroy($im);

// Output the image to browser
header('Content-Type: image/gif');
imagegif($img);
imagedestroy($img);
?>
imagestring函数仅限于内置的、相当难看的字体,并且大小选项仅为1到5。您可以使用另一个TTF字体功能,如下所述

要更改字体,您需要提供自己的TTF格式字体,请将它们与脚本放在同一文件夹中,并将imagestring函数替换为此函数。参数非常相似,您自己替换代码应该很简单。下面是解释如何使用imagettftext函数的链接