Coverting从输入和显示图像阵列与一些HTML文本 [英] Coverting array from input and display image with text with some Html

查看:227
本文介绍了Coverting从输入和显示图像阵列与一些HTML文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经包含按字母顺序排列的所有它的价值观数组:

 鳄鱼
  Α
  熊
  蜜蜂
  香蕉
  猫
  美洲狮

高达到Z现在我想的帽子,当我从我的示例HTML文件获取输入我写的名称在HTML的输入框就应该得到拆分成字母,并给输出像

  N A M E
名称
A N A V
加利T I
克邻ü大号
^ hÿř
T IË

  G

在这种方式我得与背景图像,我用我的PHP code以下,但试了很多时间没有得到结果的结果应该是相同的方式中,我已经展示了文本的图像结果
我的HTML code是:name.html

 < HTML和GT;
 <头LANG =ENGT&;
 <间的charset =UTF-8>
 <标题>< /标题>
 < /头>
 <身体GT;
 <形式的行动=result.php的方法=获取>
 <输入类型=文本ID =名称NAME =MYNAME占位符=例如:ABC>
 <输入类型=提交值=提交>
 < /表及GT;
 < /身体GT;
 < / HTML>

我的PHP code是:result.php

 < PHP标题(内容类型:image / JPEG');
$ jpg_image = imagecreatefromjpeg('Desert.jpg');
$白色= imagecolorallocate($ jpg_image,73,41,236);
$ font_path ='OpenSans-Italic.TTF';
$文字= $ _GET ['名'];
imagettftext($ jpg_image,25,0,75,50,本品为白色,$ font_path,$文字);
imagejpeg($ jpg_image);
imagedestroy($ jpg_image);
?>


解决方案

我能够对图像的顶部放置文本。我认为这是你想要什么来完成的,是吗?还请访问此示例站点(如果你还没有这样做的话)的 http://www.phpforkids.com/php/php-gd-library-adding-text-writing.php

使用标题设置为图像/ JPEG它呈现在浏览器中的图像,但是不能打印文本。

如果您输入的名字是MYNAME然后results.php的_GET参数需要匹配。 prevent使用任何多余的空格修剪变量。

$文字=修剪($ _ GET ['MYNAME']);

如果它是一个面向公众的网站,消毒输入。
http://php.net/manual/en/function.filter-var.php

I have an array that already contains all it's values in alphabetical order:

  Alligator
  Alpha
  Bear
  Bees
  Banana
  Cat
  Cougar

up to Z Now I want hat when I get Input from my Html file for Example I write "Name" in the html input box then it should get split that into alphabet and give output like

N A M E  
N A M E
A N A V
U N T I
G O U L
H Y R
T I E
Y N
  G     

In This way I must get Result with a image on background for image and text I used my Php code below but tried many time not getting the result the result should be in same manner in which I have shown My html code is:name.html

 <html>
 <head lang="en">
 <meta charset="UTF-8">
 <title></title>
 </head>
 <body>
 <form action="result.php" method="get">
 <input type="text" id="name" name="myname" placeholder="E.g: abc">
 <input type="submit" value="Submit">
 </form>
 </body>
 </html>

My php code is: result.php

<?php

header('Content-type: image/jpeg');
$jpg_image = imagecreatefromjpeg('Desert.jpg');
$white = imagecolorallocate($jpg_image, 73, 41, 236);
$font_path = 'OpenSans-Italic.TTF';
$text = $_GET['name'] ;
imagettftext($jpg_image, 25, 0, 75, 50, $white, $font_path, $text);
imagejpeg($jpg_image);
imagedestroy($jpg_image);
?>

解决方案

I was able to lay text on top of the image. I think this is what you're trying to accomplish, yes? Please also visit this sample site (if you have not done so already) http://www.phpforkids.com/php/php-gd-library-adding-text-writing.php

With header set to "image/jpeg" it renders an image in the browser but will not print text.

If your input name is 'myname' then the _GET param in results.php needs to match. Prevent any unwanted spaces using trim the variable.

$text = trim($_GET['myname']);

If it is a public-facing website, sanitize the input. http://php.net/manual/en/function.filter-var.php

这篇关于Coverting从输入和显示图像阵列与一些HTML文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆