- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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.
- Related Articles
- Display an Icon from Image Sprite using CSS
- Read an image with OpenCV and display it with Tkinter
- How to display an image in HTML?
- How to display an image in JavaFX?
- Drawing an image from a data URL to a HTML5 canvas
- Performing binary thresholding on an image using OpenCV
- How to load and display an image in ImageView on Android App?
- How to load and display an image on iOS App using Swift?
- Performing inverse binary thresholding on an image using OpenCV
- Which PHP functions are used in the PHP script to fetch data from an existing MySQL table?
- How to write PHP script to delete data from an existing MySQL table?
- Write a C program to read a data from file and display
- How can I display an image using Pillow in Tkinter?
- How can I display an image using cv2 in Python?
- Create a record array from binary data in Numpy

Advertisements