将php字符串转换为图像

将php字符串转换为图像,php,string,image,gd,Php,String,Image,Gd,我想将php字符串转换为图像。 我使用这个代码 header("Content-type: image/png"); $string = '.the_title().'; $font = 5; $width = imagefontwidth($font) * strlen($string); $height = imagefontheight($font); $image = imagecreatetruecolor ($width,$height); $white = imagecol

我想将php字符串转换为图像。 我使用这个代码

header("Content-type: image/png");
$string = '.the_title().';

$font  = 5;
$width  = imagefontwidth($font) * strlen($string);
$height = imagefontheight($font);

$image = imagecreatetruecolor ($width,$height);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);

imagestring ($image,$font,0,0,$string,$black);

imagepng ($image);
imagedestroy($image)    

但是它将标题显示为文本,而不是执行字符串使用
imagecreatefromstring

$string = '.the_title().';

$data = base64_decode($string);

$im = imagecreatefromstring($data);
if ($im !== false) {
    header('Content-Type: image/png');
    imagepng($im);
    imagedestroy($im);
}
使用类似于:


不显示anything@ninju你只是复制/粘贴php样本而没有测试…我没有测试它。它只是为了参考。为什么?这不适用于php字符串。它适用于base64编码的字符串,但这不是我的问题可能与它的不重复部分重复阅读完整的文章关于base64字符串搜索,如果
gd
phpinfo()中存在请参见gd已启用。您的代码不起作用。我可以用上面的“我的代码”和一个普通的文本字符串(返回图像)一起使用。我用字符串“test”尝试了一下,结果很好。因此,使用字符串“the_title()”;这很有效。也许哪里有打字错误。我刚刚尝试了php.net中的“imagestring代码”,并将文本字符串替换为$string。这可以工作,但只返回_title(),而不是执行php字符串。图像创建也可以使用我的代码,这不是我的问题。我的问题是_title()应该返回帖子的标题。这并没有发生,创建的图像中只有文本,而不是帖子名
<?php

$string = the_title();

$im = imagecreate(150, 20); // image size 150x20px
imagecolorallocate($im, 255, 255, 255); // background white
$text_color = imagecolorallocate($im, 0, 0, 0); // text color black

imagestring($im, 3, 5, 5, $string, $text_color); // append string to image

header('Content-type: image/png'); // filetype
imagepng($im, 'image.png'); // save as image.png
imagedestroy($im); // free up memory