linuxdo随机图片API——瞎玩玩

接着前面爬取的资源继续讨论:

创建一个图片API随机调用接口

来个成品 :wink:

https://images.linux-do.rr.nu

1.在serv00中创建PHP类型网站并绑定域名

2.修改index.html

<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Linuxdo Random Images</title>
    <style>
        body {
            margin: 0;
            padding: 0;
            font-family: Arial, sans-serif;
            background-size: cover;
            background-position: center;
            transition: background-image 1s ease-in-out;
        }

        .header {
            background-color: rgba(0, 0, 0, 0.7);
            padding: 20px;
            text-align: center;
            font-size: 2.5em;
            font-weight: bold;
            background: linear-gradient(90deg, #ff0080, #00bfff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .content {
            max-width: 800px;
            margin: 20px auto;
            padding: 20px;
            background-color: rgba(255, 255, 255, 0.8);
            border-radius: 10px;
            box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
        }

        .content h2 {
            font-weight: bold;
            font-size: 2em;
            background: linear-gradient(90deg, #ff0080, #00bfff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .api-link {
            font-size: 1.5em;
            font-weight: bold;
            background: linear-gradient(90deg, #ff0080, #00bfff);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .section {
            margin-bottom: 30px;
        }
    </style>
</head>
<body>

<div class="header">
    <h1><a href="https://linux.do" style="text-decoration:none; color:inherit;">Linuxdo Random Images</a></h1>
</div>

<div class="content section">
    <h2>随机图片说明</h2>
    <p>目前系统共收录10000+张图片。</p>
    <p>图片均为HTTPS协议,采用本地储存图,感谢https://tuapi.eees.cc站收集的图片。</p>
    <p>感谢serv00主机商提供的虚拟主机。</p>
</div>

<div class="content section">
    <h3 class="api-link">接口地址:</h3>
    <p><a href="https://你的域名/random.php" target="_blank">https://你的域名/random.php</a></p>
</div>

<script>
    function updateBackground() {
        document.body.style.backgroundImage = "url('https://你的域名/random.php?" + new Date().getTime() + "')";
    }

    setInterval(updateBackground, 15000);
    updateBackground();
</script>

</body>
</html>

域名改为你的,其余部分自行调整

3.在serv00中创建一个random.php文本

<?php
// 设置图片目录
$imageDir = 'images';

// 使用 glob 函数获取所有JPG图片
$images = glob($imageDir . '/*.jpg');

// 检查是否有图片
if (count($images) > 0) {
    // 随机选择一张图片
    $randomImage = $images[array_rand($images)];
} else {
    // 如果没有找到图片,设置一个默认图像
    $randomImage = 'images/default.jpg'; // 确保这个默认图像存在
}

// 获取文件名和扩展名
$imageInfo = pathinfo($randomImage);
$imageName = $imageInfo['basename'];

// 构建完整的图片URL
$imageUrl = 'http://' . $_SERVER['HTTP_HOST'] . '/' . $randomImage;

// 设置响应头为重定向到图片URL
header("Location: $imageUrl");
exit();

4.创建images文件

在images文件下放入你的图片,并创建.htaccess文本

Options -Indexes
10 个赞

虽然不知道有什么用,但是总会有用到地方,哪怕是点开看看调整一下心情呢,何况还是免费的。
所以,谢谢了。

https://image.namei.ggff.net/

来交作业了哈哈,没有网盘,直接转到大佬的api上去了

https://tuapi.eees.cc 这个好像也是一位大佬的,要是我这样直接转过去有问题,联系我,停掉

太强了大佬 :tieba_013: