用php将图像转换为字节

fle*_*her 6 php bytearray

我必须将图片发送到网络服务.Web服务应该以字节(mayby bytearray)的形式接收图像 - 而不是字符串...如何将图像转换为"byte"或bytearray?

我试过这个(没有成功):

$image1 = file_get_contents("LINK TO IMAGE");
$image1BinaryData = "".base64_encode($image1)."";
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激...

suc*_*nic 8

您是否尝试将图像直接读取为二进制数据?

<?php
$filename = "image.png";
$file = fopen($filename, "rb");
$contents = fread($file, filesize($filename));
fclose($file);
?>
Run Code Online (Sandbox Code Playgroud)

  • 这就是 file_get_contents() 所做的。 (2认同)