PHP Base64 Image Encoder plugin


PHP Base64 Image Encoder plugin

Base64 Image Encoder

Hai Today we come’s with a wonderful and Most useful Plugin For Every developer’s and Blogger’s PHP Base64 Image Encoder plugin two days before we releasing a Blogger Sitemap Generator PHP Plugin it’s Our First PHP Plugin.Today we are Going to Launch Our second PHP Plugin PHP Base64 Image Encoder plugin.

What is Base 64 image encoder ?

Base 64 image encoder Optimize your Image and Converted them to Data URIs Format it help us to speed up your Website loading time.Mostly image will take some time to load from HTTP request’s.Base 64 image Format directly embedded a Data URIs  into the browser it will help to reduce the HTTP requests for image and improve the website loading time.

For More about Base 64 encode in PHP read here

PHP Plugin For Base64 Image Encoder

Method 1

// Set image path
$image = 'cricci.jpg';

// Convert Image Path 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 image
echo '<img src="'.$src.'">';  
  • In line 2 Replace YOUR IMAGE URL with your image URL

Method 2

echo '<img src="'.getDataURI('path_to/your_image.png').'">';
function getDataURI($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));
}  
  • In line 1 replace path_to/your_image.png  with your image folder path or URL

Method 3

This my Custom PHP Base64 Image Encoder plugin

  • First create a PHP web page for form EX – imgencode.php
  • Next paste the below HTML Form code in that file.
<form action='output.php' method='post'>
<input type='text' name='file' required id="file" placeholder="Your Image URL"/>
<br />
<button type="submit">Convert</button>
</form>
  • Now create an output.php file for getting our Base64 Image.
 
 <?php
$var= $_POST["file"];
?> Your base64 encode image <img src="data:image/png;base64,<?php echo base64_encode(file_get_contents("$var")) ?>"> Copy base64 encode image URL : <textarea rows="10" cols="100"> data:image/png;base64,<?php echo base64_encode(file_get_contents("$var")) ?></textarea>
  • That’s all finally we installed the PHP Base64 Image Encoder plugin on our server.

Check My Base64 Image Encoder Tool

Method 4

This is very simple method directly encode our image

<img src="data:image/png;base64,<?php echo base64_encode(file_get_contents("IMAGE URL HERE")) ?>">
  • Replace IMAGE URL HERE with your image path or image URL.

Adding Base64 Image data URIs in CSS

li {
background:
url(YOUR base 64 DATA URL)
no-repeat
left center;
padding: 5px 0 5px 25px;
}

Adding Base64 Image data URLs in HTML

<img width="16" height="16" alt="star" src="YOUR Base64 Encoded image URL" />

Final Words

Base64 Image image Format will Help to improve Our website page speed if you have Any doubt’s related to PHP Base64 Image Encoder plugin please feel to comment here I will help you.

 


Was this article helpful?
Thanks!

Your feedback helps us improve Allwebtuts.com



7 Shares
+12
Tweet
Share4
Pin1
Stumble