$file = "./image.jpg"; $path = pathinfo($file); $ext = mb_strtolower($path['extension']); if (in_array($ext, array('jpeg', 'jpg', 'gif', 'png', 'webp'))) { $size = getimagesize($file); $file_img = 'data:' . $size['mime'] . ';base64,' . base64_encode(file_get_contents($file)); } ?>