构建PHP脚本以创建新映像

时间:2015-04-17 09:39:28

标签: php html image

我正在为我的个人网站创建一个新脚本。我想要某种功能,访问者可以在输入字段中写东西,然后按生成图像。

然后脚本应该拍摄背景图像并将访问者文本插入顶部。

我的问题是:实际生成图像文件的php代码是什么?如何将输入数据连接到图像?

如果你没有时间,我不需要完整的代码示例,我只需要如何设置这样一个系统的基础练习。

2 个答案:

答案 0 :(得分:2)

试试这段代码:

$filename = "layout.jpg";

$im = @imagecreatefromjpeg($filename);
$font = "tahoma.ttf";

$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 255, 255, 255);

imagettftext($im, 15, 0, 50, 50, $black, $font, $_POST['message_from_user']);

header('Content-Type: image/jpeg');

imagejpeg($im, null, 100);
imagedestroy($im);

layout.jpg是背景图片,tahoma.ttf是字体文件

两个文件都应放在同一个文件夹中。

此代码将使用用户字符串生成jpg-image。

通过搜索“gd in php”可以获得更多详细信息。

答案 1 :(得分:1)

做这样的事情:

$text = 'put ur txt here'; 

$height = 25; 

$width = 65; 

$image_p = imagecreate($width, $height); 

$black = imagecolorallocate($image_p, 0, 0, 0); 

$white = imagecolorallocate($image_p, 255, 255, 255); 

$font_size = 14; 



imagestring($image_p, $font_size, 5, 5, $text, $white); 

imagejpeg($image_p, 'file name here', 80); 
相关问题