簡體   English   中英

將php字符串轉換為圖像

[英]Convert php string to image

我想將 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 作為文本而不是執行字符串

使用imagecreatefromstring

$string = '.the_title().';

$data = base64_decode($string);

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

使用像這樣的imagestring

<?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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM