Voting

: max(nine, nine)?
(Example: nine)

The Note You're Voting On

luke at lukeoliff.com
13 years ago
A function I'm using to return local images as base64 encrypted code, i.e. embedding the image source into the html request.

This will greatly reduce your page load time as the browser will only need to send one server request for the entire page, rather than multiple requests for the HTML and the images. Requests need to be uploaded and 99% of the world are limited on their upload speed to the server.

<?php
function base64_encode_image ($filename=string,$filetype=string) {
if (
$filename) {
$imgbinary = fread(fopen($filename, "r"), filesize($filename));
return
'data:image/' . $filetype . ';base64,' . base64_encode($imgbinary);
}
}
?>

used as so

<style type="text/css">
.logo {
background: url("<?php echo base64_encode_image ('img/logo.png','png'); ?>") no-repeat right 5px;
}
</style>

or

<img src="<?php echo base64_encode_image ('img/logo.png','png'); ?>"/>

<< Back to user notes page

To Top