PHP – Image to Base64 String

<title>Image to Base64 String</title>
<legend>Image to Base64 String</legend>
<form name="select_all">
* @author vir0e5 a.k.a banditc0de
* @copyright 2010 by vir0e5
* @authorurl
* @Blog
This code will help you to learn how we can convert an image into a base64 string!!
//$file = File Image yang ingin di encode
//Filetype: JPEG,PNG,GIF
$file = "khansa.jpg";
if($fp = fopen($file,"rb", 0))
$gambar = fread($fp,filesize($file));

$base64 = chunk_split(base64_encode($gambar));
$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();;"></p>


Published by


just to remember what i had known :)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s