日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

php 文字图片怎么保存为图片,php技术实现加载字体并保存成图片

發布時間:2025/3/20 php 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php 文字图片怎么保存为图片,php技术实现加载字体并保存成图片 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

下面通過一段代碼給大家詳解介紹下php技術實現加載字體并保存成圖片。

// Set the content-type

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

// Create the image

$im = imagecreatetruecolor(400, 100);

// Create some colors

$white = imagecolorallocate($im, 255, 255, 255);

$grey = imagecolorallocate($im, 128, 128, 128);

$black = imagecolorallocate($im, 0, 0, 0);

imagefilledrectangle($im, 0, 0, 399, 100, $white);

// The text to draw

$text = '字典網';

// Replace path by your own font path

$font = 'fontName.ttf';

// Add some shadow to the text

//imagettftext($im, 60, 0, 11, 21, $grey, $font, $text);

// Add the text

imagettftext($im, 60, 0, 0, 70, $black, $font, $text);

// Using imagepng() results in clearer text compared with imagejpeg()

imagepng($im);

imagedestroy($im);

如果想保存圖可以用下面代碼

ob_start();

imagejpeg($im);

$img = ob_get_contents();

ob_end_clean();

$size = strlen($img);

$fp2=@fopen('tst.jpg', "a");

fwrite($fp2,$img);

fclose($fp2);

以上代碼就可以完成加載字體并保存成圖片,希望大家會喜歡

總結

以上是生活随笔為你收集整理的php 文字图片怎么保存为图片,php技术实现加载字体并保存成图片的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。