Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用restler返回图像_Php_Restler - Fatal编程技术网

Php 使用restler返回图像

Php 使用restler返回图像,php,restler,Php,Restler,是否可以使用Luracast Restler返回图像?比如打电话: http://myserver.com/api/users/002/avatar 要下载png?可以使用Restler提供图像 您需要在API方法中执行以下操作 为正确的图像类型(png、jpeg等)设置内容类型标题 回显图像内容 示例 $im = imagecreatefrompng("test.png"); header('Content-Type: image/png'); imagepng($im); //th

是否可以使用Luracast Restler返回图像?比如打电话:

http://myserver.com/api/users/002/avatar

要下载png?

可以使用Restler提供图像

您需要在API方法中执行以下操作

  • 为正确的图像类型(png、jpeg等)设置内容类型标题

  • 回显图像内容

    示例

    $im = imagecreatefrompng("test.png");
    
    header('Content-Type: image/png');
    
    imagepng($im); //this sends the image as the response
    imagedestroy($im);
    
  • 使用exit或die停止执行,而不是使用通常的返回结果


这听起来比我所学的要简单得多:扩展Format类以提供PNG。。。ThanksAn imageloader http客户端正在将Accept标头设置为image/*,现在Restler抱怨“内容协商失败。请尝试“应用程序/json”。我是否应该添加一个带有MIME=“image/*”的空ImageFormat类?或者有更好的方法吗?是的,您需要添加一个伪ImageFormat类
$im = imagecreatefrompng("test.png");

header('Content-Type: image/png');

imagepng($im); //this sends the image as the response
imagedestroy($im);