Home > Backend Development > PHP Problem > How to convert php images to binary

How to convert php images to binary

藏色散人
Release: 2023-03-03 15:16:02
Original
2996 people have browsed it

How to convert php images into binary: first get the image address; then open it in binary mode through the "fopen($image,'rb');" method; then read the data through the fread function; and finally output the binary Just data.

How to convert php images to binary

Recommended: "PHP Video Tutorial"

PHP converts images into binary

Get the image binary data

$image = 'images/psb.jpg';  //图片地址
$fp = fopen($image,'rb');  //以二进制模式打开
$content = fread($fp,filesize($image)); //读取
echo $content; //输出二进制数据,为乱码
Copy after login

The obtained binary data is output as an image (just add header)

header( "Content-type: image/jpeg");
$image = 'images/psb.jpg';  //图片地址
$fp = fopen($image,'rb');  //以二进制模式打开
$content = fread($fp,filesize($image)); //读取
echo $content; //输出图片
Copy after login

The above is the detailed content of How to convert php images to binary. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template