joh*_*ack 4 php gd content-type image
我的应用程序是从具有内容类型"application/octet-stream"的移动设备发送给它的图像.
我需要使用GD库处理这些图像,这意味着我需要能够从数据中创建图像对象.
通常情况下,我一直在使用imagecreatefromjpeg,imagecreatefrompng,imagecreatefromgif等来处理从Web表单上传的文件,但是当我作为application/octet-stream来找我时这些似乎不起作用.
关于如何实现目标的任何想法?
编辑
这是我用来创建图像标识符的代码...我的处理程序在我的网站中运行得很好,我在网站和iOS数据之间的唯一区别就是内容类型
public function open_image($path) {
# JPEG:
$im = @imagecreatefromjpeg($path);
if ($im !== false) { $this->image = $im; return $im; }
# GIF:
$im = @imagecreatefromgif($path);
if ($im !== false) { $this->image = $im; return $im; }
# PNG:
$im = @imagecreatefrompng($path);
if ($im !== false) { $this->image = $im; return $im; }
$this->error_messages[] = "Please make sure the image is a jpeg, a png, or a gif.";
return false;
}
Run Code Online (Sandbox Code Playgroud)
简单 :)
$image = imagecreatefromstring( $data );
Run Code Online (Sandbox Code Playgroud)
特别:
$data = file_get_contents($_FILES['myphoto']['tmp_name']);
$image = imagecreatefromstring( $data );
Run Code Online (Sandbox Code Playgroud)