![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP: recreate and display an image from binary data
This can be done using data URI in the image src attribute.
Format
data:[<MIME-type>][;charset="<encoding>"][;base64],<data> <?php function data_uri($file, $mime) { $contents = file_get_contents($file); $base64 = base64_encode($contents); return ('data:' . $mime . ';base64,' . $base64); } ?> <img src="<?php echo data_uri('some_image.png','image/png'); ?>" alt="Image sample" />
The ‘data_uri’ function defines the ‘contents’, ‘base64’ and returns the data and its encoded value. This function is called by passing an image to it, thereby recreating it and displaying it in the form of binary data.
Note − This can be used to avoid storing the images to the disk after processing them.
Advertisements