php将image转换为base64编码

来源:互联网 发布:阿里云研究中心 编辑:程序博客网 时间:2024/04/26 18:54
<?php$file = "example.jpg";$type = getimagesize( $file ); //取得图片的大小,类型等$file_content = base64_encode( file_get_contents( $file ) );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编码echo '<img src="' . $img . '" >';





1 0
原创粉丝点击