php base64图片转换的方法:1、通过“base64_encode($img_content);”方将图片转base64编码字符串;2、使用“base64_decode($img_base64);”方法将base64编码字符串转图片。

推荐:《PHP视频教程》
本教程操作环境:Windows7系统、PHP5.6版,该方法适用于所有品牌电脑。
php 图片 base64编码相互转换
立即学习“PHP免费学习笔记(深入)”;
Base64是网络上最常见的用于传输8Bit字节码的编码方式之一,Base64就是一种基于64个可打印字符来表示二进制数据的方法。
Base64编码包含26个大写字母 26个小写字母 10个数字和 加号+ 斜线 /
图片转base64编码字符串
$img = 'images/2.jpg';
$img_content = file_get_contents($img);
$img_encode = base64_encode($img_content);
$img_info = getimagesize($img);
$img_encode= "data:{$img_info['mime']};base64,".$img_encode;
echo "<img src='{$img_encode}' width='400' />";base64编码字符串转图片
//$decode_arr = explode(',',$img_encode);
$img_base64 = substr($img_encode,strrpos($img_encode,','));
$img_decode = base64_decode($img_base64);
file_put_contents('abc.png',$img_decode);以上就是php base64 图片转换的方法的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号