Home  >  Article  >  Backend Development  >  How to convert php images to binary

How to convert php images to binary

藏色散人
藏色散人Original
2020-07-31 09:28:322888browse

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; //输出二进制数据,为乱码

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; //输出图片

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!

Statement:
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