首页 >后端开发 >php教程 >php将image转换为base64编码

php将image转换为base64编码

WBOY
WBOY原创
2016-07-29 08:57:45925浏览

<code><span><?php </span><span>$file</span> = <span>"example.jpg"</span>;
<span>$type</span> = getimagesize( <span>$file</span> ); <span>//取得图片的大小,类型等</span><span>$file_content</span> = base64_encode( file_get_contents( <span>$file</span> ) );
<span>switch</span> ( <span>$type</span>[<span>2</span>] ) { <span>//判读图片类型</span><span>case</span><span>1</span>:
        <span>$img_type</span> = <span>"gif"</span>;
        <span>break</span>;
    <span>case</span><span>2</span>:
        <span>$img_type</span> = <span>"jpg"</span>;
        <span>break</span>;
    <span>case</span><span>3</span>:
        <span>$img_type</span> = <span>"png"</span>;
        <span>break</span>;
}
<span>$img</span> = <span>'data:image/'</span> . <span>$img_type</span> . <span>';base64,'</span> . <span>$file_content</span>; <span>//合成图片的base64编码</span><span>echo</span><span>'<img  src="'</span>%20.%20<span>%24img</span>%20.%20<span>'" alt="php将image转换为base64编码" >'</span>;</span></code>


').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });

以上就介绍了php将image转换为base64编码,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn