下面的代码是用php获取图片并转换为jepg格式
直接可用 <img src="bing.php"> 调用

<?php
$str=file_get_contents('https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1');

$url=json_decode($str,true);
$matches=$url['images'][0]['url'];
$imgurl='https://www.bing.com'.$matches;

if($imgurl){
header('Content-Type: image/JPEG');
@ob_end_clean();
@readfile($imgurl);
@flush(); @ob_flush();
exit();
}else{
exit('error');
}
?>

css代码添加到网站css文件或者php文件

<style>body {background-image: url("bing.php 的地址");filter:"progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='scale')";-moz-background-size:100% 100%;background-size:100% 100%;background-attachment: fixed;}</style>

写api调用时发现获取的图片总是和浏览器的不一样。
结果用我服务器ip访问就一样了。
总结就是服务器是hk的,本地是国内的输出的图片原本就不一样。

如果觉得我的文章对你有用,请随意赞赏