PHP 将图片转换成BASE64

来源:互联网 发布:淘宝玉丽佳人女裤 编辑:程序博客网 时间:2024/03/29 23:09
<!--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>



原文地址:http://blog.csdn.net/zhailulu/article/details/6175349


0 0
原创粉丝点击