PHP教學 - 利用 php 將文字轉成圖片

有需要的可以參考,simsun.ttc 就自己上網找了 
<?php

$im = imagecreatetruecolor(400, 30);            //新增400 30像素大小的畫布

$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);

imagefilledrectangle($im, 0, 0, 399, 29, $white);       //輸出一個使用白色填充的矩形作為背景

//如果有中文輸出,需要將其轉碼,轉換為UTF-8的字串才可以直接傳遞
//$text = iconv("GB2312", "UTF-8", "回憶經典");
 $text = "狀態";
//設定字體,將系統中與simsun.ttc對應的字體複製到當前目錄下
$font = 'simsun.ttc';

imagettftext($im, 20, 0, 12, 21, $grey, $font, $text);      //輸出一個灰色的字串作為陰影
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);         //在陰影上輸出一個黑色的字串

header("Content-type: image/png");
imagepng($im);

imagedestroy($im);

exit;
?>

留言

這個網誌中的熱門文章

c語言-關於#define用法

PHP教學 - 資料型態(Data Type) - 上

CMD常用網管指令