📚 图片API接口文档

快速随机获取高质量图片的API服务

🚀 快速开始

我们的图片API提供手机端和电脑端两种类型的随机图片服务,您只需要发送一个简单的GET请求即可获取适合不同设备的随机图片。

📋 基础信息

GET https://lh.ithxs.com/apis.php

📝 请求参数

参数名 类型 必填 说明 可选值
act string 必填 指定图片类型 pe | pc
💡 参数说明
  • pe - 返回手机端适用的随机图片
  • pc - 返回电脑端适用的随机图片

📤 API响应

✅ 成功响应

302 Found 重定向到随机图片URL

API会返回302重定向状态码,自动跳转到一张随机图片的直链地址。您的浏览器或HTTP客户端会自动跟随重定向显示图片。

❌ 错误响应

状态码 错误信息 原因
400 Invalid action parameter act参数无效或缺失
404 Image directory not found 图片目录不存在
404 No valid images found 目录中没有有效的图片文件

💡 使用示例

🌐 直接访问

在浏览器地址栏直接输入以下URL:

# 获取手机端图片 https://lh.ithxs.com/apis.php?act=pe # 获取电脑端图片 https://lh.ithxs.com/apis.php?act=pc

🔗 HTML中使用

HTML
<!-- 显示随机手机端图片 --> <img src="https://lh.ithxs.com/apis.php?act=pe" alt="手机端随机图片"> <!-- 显示随机电脑端图片 --> <img src="https://lh.ithxs.com/apis.php?act=pc" alt="电脑端随机图片"> <!-- 点击刷新图片 --> <img src="https://lh.ithxs.com/apis.php?act=pe" alt="手机端随机图片" onclick="this.src=this.src+'&t='+Date.now()" style="cursor: pointer;">

📱 JavaScript获取

JavaScript
// 获取随机图片URL function getRandomImage(type = 'pe') { const apiUrl = 'https://lh.ithxs.com/apis.php?act=' + type; fetch(apiUrl, { method: 'HEAD' }) .then(response => { if (response.ok) { // 获取重定向后的真实图片URL const imageUrl = response.url; console.log('图片URL:', imageUrl); // 设置到img元素 document.getElementById('myImage').src = imageUrl; } }) .catch(error => { console.error('获取图片失败:', error); }); } // 使用示例 getRandomImage('pe'); // 获取手机端图片 getRandomImage('pc'); // 获取电脑端图片

🐘 PHP中使用

PHP
<?php // 获取随机图片URL function getRandomImageUrl($type = 'pe') { $apiUrl = 'https://lh.ithxs.com/apis.php?act=' . $type; // 使用cURL获取重定向后的URL $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $apiUrl); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); $response = curl_exec($ch); $imageUrl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); curl_close($ch); return $imageUrl; } // 使用示例 $peImage = getRandomImageUrl('pe'); $pcImage = getRandomImageUrl('pc'); echo "<img src='{$peImage}' alt='手机端随机图片'>"; echo "<img src='{$pcImage}' alt='电脑端随机图片'>"; ?>

🐍 Python中使用

Python
import requests def get_random_image_url(image_type='pe'): """获取随机图片URL""" api_url = f'https://lh.ithxs.com/apis.php?act={image_type}' try: response = requests.head(api_url, allow_redirects=True) if response.status_code == 200: return response.url else: print(f"请求失败: {response.status_code}") return None except Exception as e: print(f"请求异常: {e}") return None # 使用示例 pe_image_url = get_random_image_url('pe') pc_image_url = get_random_image_url('pc') print(f"手机端图片URL: {pe_image_url}") print(f"电脑端图片URL: {pc_image_url}") # 下载图片 if pe_image_url: img_response = requests.get(pe_image_url) with open('random_pe_image.jpg', 'wb') as f: f.write(img_response.content) print("图片下载完成")

🎯 实际演示

点击下方按钮查看API返回的随机图片:

📱 手机端图片

手机端随机图片

💻 电脑端图片

电脑端随机图片

⚠️ 注意事项

🔒 使用限制
  • API目前不设置调用频率限制,但请合理使用
  • 建议在生产环境中实现适当的缓存机制
  • 大量调用时请考虑对服务器的影响
🖼️ 图片格式
  • 支持的图片格式:JPG、JPEG、PNG、GIF、WebP、BMP
  • 图片质量和尺寸由原始文件决定
  • API不会对图片进行压缩或格式转换
🚀 性能优化建议
  • 对于频繁调用的场景,建议实现客户端缓存
  • 可以通过添加时间戳参数强制获取新图片
  • 建议使用CDN来缓存和加速图片加载

📞 技术支持

如果您在使用过程中遇到任何问题,或者有功能建议,欢迎联系我们: