醉菜鸟 2021-07-09 20:27:48

PHP图片转换为Base64

/**
* @param $image_file
*/
function Base64EncodeImage($image_file){
if(file_exists($image_file) && is_file($image_file)){
$image_info = getimagesize($image_file);
$image_data = fread(fopen($image_file,'r'),filesize($image_file));
$base64_image = 'data:'.$image_info['mime'].';base64,'.chunk_split(base64_encode($image_data));
return $base64_image;
}else{
return false;
}
}
意见反馈