在图像上添加文本时出现php错误

时间:2013-03-26 10:29:13

标签: php image wordpress

你好,我是php的新手, 所以我对此并不了解。 我试图用形式方法在图像上添加文本,但这不起作用 这是代码

在form-add-text.php

 <form id="action-meme" action="mysite.com/image-process.php/">

<input name="cp" id="inputcpname" type="text" >
<input type="submit" >
</form>

这是image-process.php中的代码

  <?php
  //Set the Content Type
  header('Content-type: image/jpeg');

  // Create Image From Existing File
 $jpg_image = imagecreatefromjpeg('http://i.imgur.com/xxxYpW.jpg');

  // Allocate A Color For The Text
   $white = imagecolorallocate($jpg_image, 255, 255, 255);

  // Set Path to Font File
 $font_path = 'http://fonts.googleapis.com/css?family=Gabriela';

 // Set Text to Be Printed On Image
 $text = $_POST["cp"];

 // Print Text On Image
  imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

 // Send Image to Browser
 imagejpeg($jpg_image);

 // Clear Memory
 imagedestroy($jpg_image);
?>

如果我用一些文字替换“$ _POST [”cp“]”,那就行吗?

我无法弄明白我的作品

2 个答案:

答案 0 :(得分:3)

以表格

添加method =“post”
 <form id="action-meme" action="mysite.com/image-process.php/" method="post" >

<input name="cp" id="inputcpname" type="text" >
<input type="submit" >
 </form>

答案 1 :(得分:1)

尝试将方法添加到表单

 <form id="action-meme" action="mysite.com/image-process.php/" method="post">