0

您好,我是 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"]" 效果很好

我无法弄清楚我的工作

4

2 回答 2

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>
于 2013-03-26T10:33:45.647 回答
1

尝试向表单添加方法

 <form id="action-meme" action="mysite.com/image-process.php/" method="post">
于 2013-03-26T10:32:18.287 回答