发送图像,并使用JSON退货吗? [英] sending an image and return it using json?

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

问题描述

我尝试发送图像到web服务中使用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);

?>

从code,有什么我做错了吗?谢谢!!! :))

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

推荐答案

JSON的MIME类型为应用程序/ JSON ,所以你不能发送图像/ 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 EN codeD,所以如果你坚持这样做的这样,请致电的 base64_en code() 第一就可以了。

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天全站免登陆