Php Base64 Encoded Image From Url

If you want to speed up your web site, you should to read this article.

php-base64-encoded-image-from-url

Base64 is an encoding format that represent binary data. Using base64 encoding to decrease network request. Thus,

[php]
// A few settings
$image = ‘cricci.jpg’;

// Read image path, convert to base64 encoding
$imageData = base64_encode(file_get_contents($image));

// Format the image SRC: data:{mime};base64,{data};
$src = ‘data: ‘.mime_content_type($image).’;base64,’.$imageData;

// Echo out a sample image
echo ‘<img src="’,$src,’">’;
[/php]

With the image data in base64 format, the last step is placing that data within the data URI format, including the image’s MIME type. This would make for a good function:

[php]
function getDataURI($image, $mime = ”) {
return ‘data: ‘.(function_exists(‘mime_content_type’) ? mime_content_type($image) : $mime).’;base64,’.base64_encode(file_get_contents($image));
}
[/php]

You can learn more information about base64 encode images