1 - Encoder une image en base64
function base64_encode_image ($filename=string,$filetype=string) {
if ($filename && is_file($filename)) {
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
return 'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
} else {
$const = strtoupper(str_replace('.'.$filetype,'',$filename));
if (defined($const)){return constant($const);} else {return null;}
}
}