PHP-从字节数组获取图像 [英] PHP - get image from byte array

查看:333
本文介绍了PHP-从字节数组获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为我的移动应用程序创建一个后端.我将图像的内容作为字节数组发送到HTTP请求的主体(输出流)中,我想在PHP脚本中读取此字节流并获取图像.

I am trying to create a back-end for my mobile application. I am sending an image's contents as a byte array in the HTTP request's body (output stream) I want to read this stream of bytes in the PHP script and get back an image.

有人可以告诉我我该怎么做吗?

Can someone please tell me how I can do that?

谢谢.

推荐答案

您可以通过阅读如何处理这些数据取决于您自己.您可以使用 file_put_contents 将数据写入文件.正如您所提到的,它是图像数据,您也许还可以将数据放入带有 Imagick :: readImageBlob 的ImageMagick 对象.另一种选择是使用 GD 并使用 imagecreatefromstring .

What you do with that data is up to you. You could write the data to a file with file_put_contents. As you mentioned it is image data, you might also be able to drop the data into an ImageMagick object with Imagick::readImageBlob. Another alternative is to use GD and load the image with imagecreatefromstring.

这篇关于PHP-从字节数组获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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