当前位置:网站首页>Build your own random wallpaper API for free

Build your own random wallpaper API for free

2022-07-05 07:30:00 SongErrors

Use github Store image +jsdelivr CDN To speed up access

Come to my station to read : Early station

1、 Create a new one github Open warehouse

Such as wallpaper-transverse

2、 Upload picture files to github Warehouse

Before uploading, the file processing batch command is 0.jpg、1.jpg2、2.jpg……

3、 To configure jsdelivr Speed up

Copy any picture and link to https://www.jsdelivr.com/github convert to jsdelivr link

 To configure jsdelivr Speed up

Such as https://github.com/UniqueYou/wallpaper-transverse/blob/main/0.jpg Convert to
https://cdn.jsdelivr.net/gh/UniqueYou/[email protected]/0.jpg

4、 Create a random.php File upload to web The server

[scode type=“blue”] Need to change to your own $picpath Address and random number [/scode]

<?php
// Initialize the random number generator , This line of code can also be deleted 
$seed = time();
// Get random numbers 
$num = mt_rand(0,98);
// Splice picture address 
$picpath = "https://cdn.jsdelivr.net/gh/UniqueYou/[email protected]/".$num.".jpg";
// Relocate to picture 
die(header("Location: $picpath"));
?>

[scode type=“green”] Recommended mt_rand() instead of rand()[/scode]
mt_rand() Function USES Mersenne Twister The algorithm generates random integers .
Tips : This function is a better choice for generating random values , The speed of returning results is rand() Functional 4 times . Tips : If you want one between 10 and 100 Between ( Include 10 and 100) Random integer of , Please use mt_rand (10,100).

[scode type=“green”] You can also use my API[/scode]
https://www.songonline.top/random.php

原网站

版权声明
本文为[SongErrors]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140555056332.html