PHP将image转换为base64字符串
PHP将image转换为base64字符串 下面的php代码将图片转换成base64格式的字符串:```{.php}lt;titlegt;Image to Base64 Stringlt;/titlegt;lt;fieldsetgt; lt;legendgt;Image to Base64 Stringlt;/legendgt; lt;centergt;
下面的php代码将图片转换成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>
精彩图集
精彩文章