用PHP将图像转换为字节 [英] Convert image to byte with php

查看:111
本文介绍了用PHP将图像转换为字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须将图片发送到Web服务。 Web服务应该以字节(可能是字节数组)的形式接收图像,而不是以字符串的形式接收图像。如何将图像转换为字节或字节数组?

I have to send a picture to a webservice. The web service should receive the image as bytes (mayby bytearray) - not as a string... How do I convert the images to "byte" or bytearray?

I尝试过此操作(没有成功):

I have tried this (without succes):

$image1 = file_get_contents("LINK TO IMAGE");
$image1BinaryData = "".base64_encode($image1)."";

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

Any help will be appreciated...

推荐答案

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

Have you tried to directly read the image as binary data?

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

这篇关于用PHP将图像转换为字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆