後端
//$imagePath是圖片本地鏈接
$imgData = file_get_contents($imagePath);
$img_info = getimagesize($imagePath);
$file_content = base64_encode($imgData);
//判读图片类型
switch ($img_info[2]) {
case 1:
$img_type = "gif";
break;
case 2:
$img_type = "jpg";
break;
case 3:
$img_type = "png";
break;
}
$img_base64 = 'data:image/' . $img_type . ';base64,' . $file_content;//合成图片的base64编码
前端顯示
const logoDom = document.getElementById('companylogo');
console.log(logoDom);
this.imgsrc = "<?php echo $imgsrc; ?>"