PHP 将图片数据BASE64编码

来源:互联网 发布:守望先锋性能数据thp 编辑:程序博客网 时间:2024/04/25 17:41
<!--content:根据图片的类型将其自动编码成base64author:zhailuluDate:2010.12.14--><html><head><?php$file="images/2.gif";$type=getimagesize($file);//取得图片的大小,类型等$fp=fopen($file,"r")or die("Can't open file");$file_content=chunk_split(base64_encode(fread($fp,filesize($file))));//base64编码switch($type[2]){//判读图片类型case 1:$img_type="gif";break;case 2:$img_type="jpg";break;case 3:$img_type="png";break;}$img='data:image/'.$img_type.';base64,'.$file_content;//合成图片的base64编码fclose($fp);?></head><body><img id="img1" src="<?php echo $img;?>"/></body></html>

0 0
原创粉丝点击