function base64_img($file) {
        $img_data = file_get_contents($file);
        $type = getimagesize($file); // Get the binary stream image format
        return 'data:'.$type['mime']. '; base64,' . chunk_split(base64_encode($img_data));
    }
Copy the code