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

How to convert images into binary streams in php

藏色散人
藏色散人Original
2021-03-11 09:02:553653browse

php method to convert an image into a binary stream: first create a PHP sample file; then use the "function binaryEncodeImage($img_file){...}" method to convert the image into a binary data stream.

How to convert images into binary streams in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

php image conversion binary data stream

/* 图片转化为二进制数据流 */
function binaryEncodeImage($img_file) {
    $p_size = filesize($img_file);
    $img_binary = fread(fopen($img_file, "r"), $p_size);
    return $img_binary;
}
 
/* 二进制数据流存储为图片 */
 
file_put_contents(图片路径, $data);

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to convert images into binary streams in php. 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