PHP Output Image 2 Browser (base64)

Output image directly to browser using base64 encoding, it means there is no file linked in src attribute. Useful if you don't want image to be indexed.

function image64($file){
    $extension = explode(".", $file);
    $extension = end($extension);

    $binary = fread(fopen($file, "r"), filesize($file));

    return '<img alt="" src="data:image/'.$extension.';base64,'.base64_encode($binary).'"/>';
}


Usage:

echo image64("test.jpg")
©2009-2011 Webarto • web design & development • Tuzla // Sarajevo // Beograd