加入收藏 | 设为首页 | 会员中心 | 我要投稿 安卓应用网 (https://www.0791zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > PHP > 正文

将图片转成base64字符串的PHP代码

发布时间:2020-05-25 06:58:11 所属栏目:PHP 来源:互联网
导读:将图片转成base64字符串的PHP代码

下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。

脚本之家小编现在分享给大家,也给大家做个参考。

此代码将帮助你学习如何将图像转换成一个base64字符串。
<title>Image to Base64 String</title>
<fieldset>
    <legend>Image to Base64 String</legend>
        <center>
        <form name="select_all">
                 <?php
                /**
 * @author vir0e5 a.k.a banditc0de
 * @copyright 2010 by vir0e5
 * @authorurl http://facebook.com/vir0e5.vbs
 * @Blog http://banditc0de.blogspot.com
  This code will help you to learn how we can convert an image into a base64 string!!
 */
                    echo"<h3><p>Image</p></h3>";
                    //$file = File Image yang ingin di encode 
                    //Filetype: JPEG,PNG,GIF
                    $file = "encode.jpg";
                    if($fp = fopen($file,"rb",0))
                    {
                    $gambar = fread($fp,filesize($file));
                    fclose($fp);

                    
                    $base64 = chunk_split(base64_encode($gambar));
                    //Result
                    $encode = '<img src="data:image/jpg/png/gif;base64,' . $base64 .'" >';
                    echo $encode;
                    }    
                ?>
                <br><textarea name="text_area" rows="20" cols="70"> <? echo $encode; ?> </textarea>
                <p><input type="button" value="Select All Code" onClick="javascript:this.form.text_area.focus();this.form.text_area.select();"></p>
        </form>
        </center>
    </fieldset>

以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。

(编辑:安卓应用网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读