我正在尝试使用单独的图像打印用户个人数据,如姓名,电子邮件,电话号码,而不是在页面上以明文打印,从而可能由Google获取缓存。尝试打印如下:
名称 - 在飞行中创建名称文字的图像
电子邮件 - 在飞行中创建电子邮件文本的图像
Phoneno - 在飞行中创建的带有数字文本的图像
我提供的代码将文本合并到一个图像即名称,但只允许我创建一个图像发送回浏览器,我怎样才能让我的脚本将多个图像发送回浏览器?
我尝试在我的函数函数'create_image($ name,$ email,$ number)中添加更多参数,但只打印一个字段到浏览器,也许与header()有关?
<?php
//Send a generated image to the browser
$name="Bob";$email="bob@email.co.uk";$number="12345678901";
create_image($name);
function create_image($value)
{
//Set the image width and height
$width = 250;
$height = 20;
//Create the image resource
$image = ImageCreate($width, $height);
//We are making three colors, white, black and gray
$white = ImageColorAllocate($image, 255, 255, 255);
$black = ImageColorAllocate($image, 0, 0, 0);
$grey = ImageColorAllocate($image, 204, 204, 204);
//Make the background black
ImageFill($image, 0, 0, $black);
//Add randomly generated string in white to the image
//imagestring ( resource $image , int $font-(font size) , int $x-(from left) , int $y-(from right) , string $string , int $color-(font-colour) )
ImageString($image, 5, 10, 3, $value, $white);
//Tell the browser what kind of file is come in
header("Content-Type: image/jpeg");
//Output the newly created image in jpeg format
ImageJpeg($image);
//Free up resources
ImageDestroy($image);
}
?>
感谢您的回复
答案 0 :(得分:0)
$name="Bob";$email="bob@email.co.uk";$number="12345678901";
switch ($_GET['option']) {
case 'name':
create_image($name);
break;
case 'email':
create_image($email);
break;
case 'number':
create_image($number);
break;
}
使用scriptname.php?option=name
答案 1 :(得分:0)
这不是一个最佳实践,但我会尝试更改您的功能,它将图像保存到文件中,并在theres是有效文件时返回文件路径。 因此,您不必创建每个调用新图像(速度很慢),并且您获得了有效的文件路径,这意味着您不必关心标题等等