欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php实现加载字体并保存

程序员文章站 2022-03-10 11:08:04
...
本篇文章主要介绍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中缓存技术的原理、特点及用法

PHP中那些经常混淆的知识点

以上就是php实现加载字体并保存的详细内容,更多请关注其它相关文章!