Home > Article > Backend Development > PHP怎么把网页内容原封不动的给生成图片
PHP如何把网页内容原封不动的给生成图片?
<br /><?php<br />$str = '<meta http-equiv="Content-Type" content="text/html; charset=gbk"><div><font color="red">文字信息</font><br><font>换行</font></div>';<br />$font_file = "方正美黑_GBK.ttf";//字体设置部分linux的路径<br />$text = $str; //要显示的字符串<br />$font_size = 14; //字体大小<br />$arr = imagettfbbox($font_size,0,$font_file,$text); //确定会变化的字符串的位置<br />$text_width = ($arr[2]-$arr[0])+10; //字符串文本框长度<br />$text_height = ($arr[3]-$arr[5])+50; ////字符串文本框高度<br /><br />$im = imagecreate($text_width,$text_height);<br />$white = imagecolorallocate($im,255,255,255);<br />imagecolortransparent($im,$white); //imagecolortransparent() 设置具体某种颜色为透明色,若注释<br />$blue = imagecolorallocate($im,0,0,0);<br /><br />$arr = imagettftext($im,$font_size,0,0,$text_height-50,$blue,$font_file,$text);<br />imageline($im,$arr[0],$arr[1],$arr[2],$arr[3],$blue);<br />//imagettftext($im,12,0,0,20,$black,"c:\windows\Fonts\simhei.ttf",$url);//字体设置windows的路径<br /><br />header("Content-type:image/png");<br />imagepng($im);<br />imagedestroy($im);<br />?><br />