PHP - 如何将图像源显示为 img
PHP - How to display image source as an img
我正在使用 Wialon SDK,我正在尝试 get a map,一切正常,但它 returns 带有图像代码的结果,并输出一些问号,(不知道如何解释一下,但是当你在记事本或类似的东西中打开 img 文件时)我如何将输出保存到 png 文件或在网络上显示它?
这里是函数
function get_map($sid){
$params = array(
"width" => 600,
"height" => 600
);
$url = "mywebpage.com/ajax.html?svc=report/get_result_map";
$json = json_encode($params);
$ch = curl_init($sid);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"¶ms=".$json."&ssid=".$sid);
$server_output = curl_exec($ch);
curl_close($ch);
return $server_output;
}
我这样称呼它:
$get_map = $pro->get_map($sid);
var_dump($get_map);
在 PHP 中,您需要设置 HEADER 以告知浏览器将此数据显示为图像。
<?php
header('Content-Type: image/png');
echo $get_map; // The PNG data
?>
这应该可以解决问题。
我正在使用 Wialon SDK,我正在尝试 get a map,一切正常,但它 returns 带有图像代码的结果,并输出一些问号,(不知道如何解释一下,但是当你在记事本或类似的东西中打开 img 文件时)我如何将输出保存到 png 文件或在网络上显示它?
这里是函数
function get_map($sid){
$params = array(
"width" => 600,
"height" => 600
);
$url = "mywebpage.com/ajax.html?svc=report/get_result_map";
$json = json_encode($params);
$ch = curl_init($sid);
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,"¶ms=".$json."&ssid=".$sid);
$server_output = curl_exec($ch);
curl_close($ch);
return $server_output;
}
我这样称呼它:
$get_map = $pro->get_map($sid);
var_dump($get_map);
在 PHP 中,您需要设置 HEADER 以告知浏览器将此数据显示为图像。
<?php
header('Content-Type: image/png');
echo $get_map; // The PNG data
?>
这应该可以解决问题。