How to add an image as a site background?

        Add page background image function is actually very simple, here to share two ways: one is to add a custom picture as the background, and the other is to add bing daily picture as the background.

        The first add a custom picture as the background, simply add the following code to the </ head> tag header file:

<style>body {background-image: url("图片地址,本博客使用的是{$host}zb_users/theme/{$theme}/image/background.png");background-position:left top;background-size:auto;background-repeat:repeat;background-attachment:scroll;}</style>
 

 

 

        The second bing add daily picture as the background, the following steps need to achieve :

(1) use notepad ++ or other professional web editor, create a new php file with the following content, such as a file named bing.php.

<?php$str=file_get_contents('http://cn.bing.com/HPImageArchive.aspx?idx=0&n=1');if(preg_match("/<url>(.+?)<\/url>/ies",$str,$matches)){$imgurl='http://cn.bing.com'.$matches[1];}if($imgurl){header('Content-Type: image/JPEG');@ob_end_clean();@readfile($imgurl);@flush(); @ob_flush();exit();}else{exit('error');}?>
 

 

    (2) save uploaded to the web root directory (or elsewhere, fill in the correct path to the file bing.php In the third step), and then access bing.php file, you will find is already a daily bing pictures. This bing.php file by php convert the picture to jepg format , that is, bing.php although that is a php file, but in fact it is a jepg file, you can <img src = "bing.php" > this code to show the picture.

    (3) Open the file header.php such sites, add the following code in the </ head> tag:

<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>
 

 

        At this point, after you refresh the website you can see bing daily pictures.

 

        Both of these methods are actually the same, but the method of application of a specified picture, another method is a reference to the daily pictures bing, this method is suitable for all sites using PHP establishment of the station Oh.

Published 16 original articles · won praise 6 · views 10000 +

Guess you like

Origin blog.csdn.net/xiegr71/article/details/105376265