Skip to content

Instantly share code, notes, and snippets.

@Zorono
Last active September 9, 2018 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zorono/64cdb80c21c20aaec10b34a8ca1df198 to your computer and use it in GitHub Desktop.
Save Zorono/64cdb80c21c20aaec10b34a8ca1df198 to your computer and use it in GitHub Desktop.
Image Base64 Encoding...(PHP)
<?php
$img_url = (preg_match('/\%[0-9A-F]{2}|\+/', $_GET['url']) !== False ? urldecode($_GET['url']) : $_GET['url']);
if($img_content = @file_get_contents($img_url))
{
if(strlen(mime_content_type($img_url)) > 2 ? strpos(mime_content_type($img_url), 'image/') !== False : True)
{
$_finfo = new finfo();
$img_mime = $_finfo->file($img_url, FILEINFO_MIME_TYPE);
echo '<img src="data:' .(isset($img_mime) && strlen($img_mime) > 2 ? $img_mime : "image/jpeg"). ';base64,' .base64_encode($img_content). '" />';
}
else
{
header("HTTP/1.0 404 Not Found");
}
}
else
{
header("HTTP/1.0 404 Not Found");
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment