0
我试图在php中渲染函数调用生成的图像。通过函数调用在html src中为图像创建文本
我已经复制粘贴在PHP找到的功能为孩子和在这里的其他地方找到。
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);
}
我打电话的功能如下:
Print ('<img itemprop="image" src="');
txt_to_png($my_text_input);
Print ('">');
,但它不能正确渲染图像:
<img itemprop="image" src="�����JFIF���������>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(��="" (��="" (��?��"="">
感谢您的帮助! Bill
谢谢,是的这个工程。只是想知道是否仍然保持该功能不变,并通过src =“渲染一些src =”data:image/jpeg; base64,..... – 2014-11-21 13:25:57