Php implements base64 display of images,

Source: Internet
Author: User

Php implements base64 display of images,

This example describes how php implements base64 display of images. We will share this with you for your reference. The details are as follows:

The image is saved to the webpage as a string, so you do not need to load the image.

This is the Data URI scheme defined in RFC2397. It aims to embed some small Data directly into the webpage, so that it does not need to be loaded from external files, such as the above string of characters, it is actually an image. copy and paste these characters to the address bar of Firefox and go to it.

In the preceding Data URI, data indicates the protocol name for obtaining Data. image/jpeg indicates the data type name, And base64 indicates the Data encoding method, the comma is followed by the base64 encoded data of the image/jpeg file.

Currently, Data URI scheme supports the following types:

Data: text/plain, text data
Data: text/html, HTML code
Data: text/html; base64, base64 encoded HTML code
Data: text/css, CSS code
Data: text/css; base64, base64 encoded CSS code
Data: text/javascript, javascript code
Data: text/javascript; base64, base64 encoded Javascript code
Data: image/gif; base64, base64 encoded gif image data
Data: image/png; base64, base64 encoded png image data
Data: image/jpeg; base64, base64 encoded jpeg image data
Data: image/x-icon; base64, base64 encoded icon image data

The php code is as follows:

$img_file = 'https://img.alicdn.com/bao/uploaded/TB1eaiELpXXXXcPXpXXSutbFXXX.jpg';$img_info = getimagesize($img_file);$img_src = "data:{$img_info['mime']};base64," . base64_encode(file_get_contents($img_file));exit("

PS: I would like to recommend several online image tools for your reference.

Online tools for converting images to Base64 encoding:
Http://tools.jb51.net/transcoding/img2base64

Online Email icon creation tools:
Http://tools.jb51.net/email/emaillogo

Online PS image processing tools:
Http://tools.jb51.net/aideddesign/webps

Online image format conversion (jpg/bmp/gif/png) tool:
Http://tools.jb51.net/aideddesign/picext

ICO icon generation tool:
Http://tools.jb51.net/aideddesign/ico_img

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.