<?php
//圖片轉成base編碼
$file="images/2.gif";
$type=getimagesize($file);//取得圖片的大小,類型等
$file_content = base_encode(file_get_contents($file));
$img='data:image/'.$img_type.';base64,'.$file_content;//合成圖片的base64編碼
echo '<img src= '. $img .'>'
?>
<?php
//編碼轉成圖片
$url = explode(',',$file_content);
file_put_contents('./test.png',base64_decode($url[1]));//存儲圖片到對應的位置