发送图像并使用json返回它? [英] sending an image and return it using json?

查看:24
本文介绍了发送图像并使用json返回它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 json 将图像发送到 php 中的网络服务,但是客户端 cnt 读取了图像..当我退货时!!

im trying to send image to a webservice in php using json, but the client cnt read the image.. when i return it back!!

<?php

//recieve the image

$media = json_decode($_POST['media']);

header('content-type: image/jpeg');
$image = imagecreatefromjpeg($media);
imagefilter($image,IMG_FILTER_GRAYSCALE);
imagefilter($image,IMG_FILTER_COLORIZE,100,50,0);
imagejpeg($image, '', 90);
imagedestroy($image);

//return image

$response = array(  
         'image' => $image
     );  
     echo json_encode($response);

?>

从代码来看,我做错了什么吗?谢谢!!!:))

from the code, is there anything I'm doing wrong? Thanks!!! :))

推荐答案

JSON MIME 类型是 application/json,所以不能发送 image/jpeg.

The JSON MIME type is application/json, so you can't send image/jpeg.

我认为发送图像的路径并让您的 JavaScript 向图像发出请求会更容易.

I think it would be easier to send the path to the image, and have your JavaScript make the request to the image.

否则,我不确定您将如何在客户端上重新创建它.日期 URI 建议使用 base64 编码,所以如果你坚持这样做,请调用 base64_encode() 先就可以了.

Otherwise, I'm not sure how you are going to recreate that on the client. Date URIs are recommended to be base64 encoded, so if you insist on doing it like this, please call base64_encode() first on it.

这篇关于发送图像并使用json返回它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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