将php字符串转换为图像

时间:2015-10-20 10:10:39

标签: 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 = 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)    

但它将the_title显示为文本而不是执行字符串

2 个答案:

答案 0 :(得分:2)

使用imagecreatefromstring

$string = '.the_title().';

$data = base64_decode($string);

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

答案 1 :(得分:1)

使用imagestring之类的:

library(stringr)
do.call(rbind, lapply(str_extract_all(df$col, '\\d+'), 
         function(x) head(as.numeric(x),2)))