dsgwdigu84950 2014-11-21 13:04
浏览 99
已采纳

创建文本到图像以通过函数调用在html src中呈现

I'm trying to render an image generated by a function call in php.

I've copy pasted a function found at php for kids and found elsewhere here.

 function txt_to_png($textin){
  //Set the Content Type
  header('Content-type: image/jpeg');
  // Create Image From Existing File
  $jpg_image = imagecreatefromjpeg('../images/100.jpg');
  // Allocate A Color For The Text
  $white = imagecolorallocate($jpg_image, 255, 255, 255);
  // Set Path to Font File
  $font_path = '../fonts/lato-regular.ttf';;
  // Set Text to Be Printed On Image
  $text = "This is a sunset!"; // just hardcoding for moment
  // 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);
 }

I am calling the function as follows:

Print ('<img itemprop="image" src="');
txt_to_png($my_text_input);
Print ('">');

but it's not rendering the image correctly:

<img itemprop="image" src="�����JFIF���������&gt;CREATOR: gd-jpeg v1.0 (using IJG JPEG v90), default quality
���C�     

 $.' " ,#(7),01444'9="82<.342���C" ="" ="" 2!!22222222222222222222222222222222222222222222222222����d�d"��������������="" �������}�!1aqa"q2���#b��r��$3br�="" %&'()*456789:cdefghijstuvwxyzcdefghijstuvwxyz�����������������������������������������������������������������������������������="" ������w�!1aqaq"2�b����="" #3r�br�="" $4�%�&'()*56789:cdefghijstuvwxyzcdefghijstuvwxyz���������������������������������������������������������������������������="" ��?��j(��="" (��="" (��?��"="">

Thanks for any help! Bill

  • 写回答

1条回答 默认 最新

  • dras2334 2014-11-21 13:09
    关注

    Your txt_to_png function is creating an image as a binary code. You need to add src="somefile.php?textin=abcd and in the somefile.php call your function with parameter txt_to_png($_GET['textin]);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路