Wednesday, August 20, 2014

php image data uri

8/20/2014

To create data uri in php, read image (png, gif, jpg) file with file_get_contents and convert it to base64 using base64_encode. Using Data URIs you can reduce network requests. But, Please keep in mind if you plan on using data URIs, they are not supported by ie7 and lower.
<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/


function createDataURI($image,$mime='') {

    $finfo = new finfo(FILEINFO_MIME_TYPE);

    $mime = $finfo->buffer(file_get_contents($image));

    return 'data:'.$mime.';base64,'.base64_encode(file_get_contents($image));
}

?>

How to  create data uri

<?php
/*
Online PHP Examples with Source Code
website: http://4evertutorials.blogspot.com/
*/


echo '';

?>

helpful? Share this

The Editorial Team of 4everTutorials consists of a group of PHP Professionals.

0 comments:

 

© 2014 4everTutorials. All rights resevered.

Back To Top