前言
图片API接口的用于很广泛,如网站背景、App背景、软件背景、头像等;在开发的时候或许可以采用第三方API;但是如果提供商倒闭、跑路等诸多因素导致不稳定;所以不管什么东西自己有是最好的。下面就给大家小写一个api的代码;使用简单,只需将下面的代码保存为一个php文件(如image.php)再上传到服务器访问:你的域名/image.php 即可
需要注意的是:在使用前需要自行设置图片源,在网站目录同文件夹内创建一个为“url.txt”的文件,将图片链接放入这个“url.txt”文本内,在访问 你的域名/image.php 就可以看到图片随机输出了。由于博主也没有大量的图包;就在本页提供仅存的百来张图片源吧,图片源用的阿里云的OSS,没做防盗链、没做跨域限制可以随便调用。如果你有图包也可以发送给我哦
图片API
<?php
// 图片文件夹路径
$imageFolder = 'url.txt';
// 获取图片文件夹中的所有图片文件
$images = glob($imageFolder . '/*.{jpg,jpeg,png,gif}', GLOB_BRACE);
// 随机选择一张图片
$randomImage = $images[array_rand($images)];
// 设置响应头为图片类型
header('Content-Type: image/jpeg');
// 输出图片
readfile($randomImage);
?>
调用示例
<img src="你的API接口地址" >
图片源:
https://r2.xk.ee/image/5C3C91AEF0400719342D3E605824449E.jpg
https://r2.xk.ee/image/5C9C2E101A22AEEDAFE26BC4135FB9AA.jpg
https://r2.xk.ee/image/5DBC0217A2922E3E26DCD3DF34A89F49.jpg
https://r2.xk.ee/image/06BE4CB526CAC5DEF88585F40B9D395C.jpg
https://r2.xk.ee/image/6B352884352E5E666F39B3E8C052C81F.jpg
https://r2.xk.ee/image/7A43C825F4330519E727FC34E70B8898.jpg
https://r2.xk.ee/image/7A40305E0BA4176D885034092EE62892.jpg
https://r2.xk.ee/image/7A4310030EE925768DC1C4B54C775F52.jpg
https://r2.xk.ee/image/7B55CEF1B34EB56A369E11F89C0BA804.jpg
https://r2.xk.ee/image/8B07D99A82421BBD4DAE7A32233E8F54.jpg
https://r2.xk.ee/image/8EE1027E64F38CEAF10119FE7F6D90B9.jpg
https://r2.xk.ee/image/8F5A50CB30CF7B11D41D8103E297D061.jpg
https://r2.xk.ee/image/009BC48106A09B9671CB857EAF72029F.jpg
https://r2.xk.ee/image/9EE7F046E0FEA79BDA19BDA1ED42C7E4.jpg
https://r2.xk.ee/image/14DBB8588CC6B98037A1CF1EC28EA53C.jpg
https://r2.xk.ee/image/19EFAFAB309AEBD4E15F99DC28B627BD.jpg
https://r2.xk.ee/image/21FB6B50FEA731F0EEE5F5588D831666.jpg
https://r2.xk.ee/image/42F8FB783881DAEB8233C53D3BF01BB4.jpg
https://r2.xk.ee/image/47A870DFA5EF42E86947D22A8D126710.jpg
https://r2.xk.ee/image/57D9C4A11040E6298723829DD92D4480.jpg
https://r2.xk.ee/image/061E5C608674CB24FB9CDF68C9D4C120.jpg
https://r2.xk.ee/image/62C286B1823581844CFE63147EAE1156.jpg
https://r2.xk.ee/image/66D77B5AAC251A0EF3473F04FBEF04C6.jpg
https://r2.xk.ee/image/67F53F5D5111CFA38B76C10753674656.jpg
https://r2.xk.ee/image/69BEECB2C4970664F16DCDFD7E72FDD0.jpg
https://r2.xk.ee/image/77BF8E78250D812324D64FAB5CB61F1D.jpg
https://r2.xk.ee/image/82FC8A21918B7E1B84C82C27FF513EB8.jpg
https://r2.xk.ee/image/83B2576C5D98F55A2EC2499B858F3514.jpg
https://r2.xk.ee/image/88DDBFBEEC14D214CCC20585589B2F47.jpg
https://r2.xk.ee/image/97AEBCB8B4576F4DE7A5439770D83018.jpg
https://r2.xk.ee/image/148B62D6D4AF8A0C042B3FBA20E7E95D.jpg
https://r2.xk.ee/image/228A4D2C59BEF5FD6AF85F94033CD2C2.jpg
https://r2.xk.ee/image/274B3F20811E8BD301E7AFFCA6883E60.jpg
https://r2.xk.ee/image/603D0E6CE26F57E077D7A531776053D4.jpg
https://r2.xk.ee/image/806FEBB5E5A2FF4D5A5C357FA5306ABA.jpg
https://r2.xk.ee/image/2155B1F6EC30EB00D220BA529E450748.jpg
https://r2.xk.ee/image/3461EEE6A4066B7638741872B991E999.jpg
https://r2.xk.ee/image/7622A5F3738A34568D86E08AF9A59A38.jpg
https://r2.xk.ee/image/12125D6CD8088A7BD3F20312CEB73012.jpg
https://r2.xk.ee/image/331675B8922A38C56BB4456111209356.jpg
https://r2.xk.ee/image/524872CAFEFC55589EC90F6B28F2B65D.jpg
https://r2.xk.ee/image/984381E0C010928FA27FC802252DCF43.jpg
https://r2.xk.ee/image/41134997E321B172154B16FE4B373AB9.jpg
https://r2.xk.ee/image/284539178F05C05DACA09478B9A2A4F6.jpg
https://r2.xk.ee/image/9328081088B24C9B0C67DACD38195468.jpg
https://r2.xk.ee/image/7420258297868CCA59A44EAC26E7EAB3.jpg
https://r2.xk.ee/image/AE71DD591378EE055E7EAF9E4E94127D.jpg
https://r2.xk.ee/image/B50972BD81D10D8B82B78A109969D399.jpg
https://r2.xk.ee/image/C1E6643D3C2E2CDD597A537D36035D39.jpg
https://r2.xk.ee/image/C8F86DAAA33C3F2FDA0C1B943744234C.jpg
https://r2.xk.ee/image/C67C78143CFA18C3F4478EAB76329A5C.jpg
https://r2.xk.ee/image/C7311A1BFB2E979E97B38215BC687212.jpg
https://r2.xk.ee/image/CAFCEE7595A66B9CD6C6FB38B10DD7B6.jpg
https://r2.xk.ee/image/D0187BB932337D07008C23B74A3DFD34.jpg
https://r2.xk.ee/image/DD3884E3653192C9D82A111CB131271E.jpg
https://r2.xk.ee/image/E0FB6B76D7CD164EB7F641E5856790DD.jpg
https://r2.xk.ee/image/E32D28569FC1EF6C6C8153C642DF4679.jpg
https://r2.xk.ee/image/E5285D25599D1F86BFC112EAB8C89D36.jpg
https://r2.xk.ee/image/E108211A18B20DBC2E07AE69374D6A34.jpg
https://r2.xk.ee/image/EDD7C8DD826DE5D91BD42E5E879F5EAA.jpg
https://r2.xk.ee/image/EDF2B07413D75194C04BA81538BAC583.jpg
https://r2.xk.ee/image/F2BAE70696F3973C9485AE04E5B771D3.jpg
https://r2.xk.ee/image/FD21E8EF6F9B2BD9E4EAD3C9B28DA5D0.jpg
https://r2.xk.ee/image/FDE79685E6B47818F9EAC0C9CAEDE6DC.jpg
https://r2.xk.ee/image/FE399F70E19678A2B85F7B56B2F70344.jpg
https://r2.xk.ee/image/0BA7E7501714BBABC218F2AE08D559F9.jpg
https://r2.xk.ee/image/1A043324D6E95F426F64ABA2DADF1965.jpg
https://r2.xk.ee/image/1AD32D687AE3AF51D0AF8B72D9D4E184.jpg
https://r2.xk.ee/image/1AF57582F0D0F9479F3900CB102AD00D.jpg
https://r2.xk.ee/image/2ACEA70C37F9DD343F6DC6B7F6A299C8.jpg
https://r2.xk.ee/image/2D1A9E5C93451606C39C90C663EEC1F4.jpg
https://r2.xk.ee/image/3AADAC2B46F6B7561B78D37DBA8F331D.jpg
https://r2.xk.ee/image/3B5150AB6111D3EAEB1E609C5FCBF089.jpg
https://r2.xk.ee/image/4B936E8A8020BCF1142159F69590DBD7.jpg
https://r2.xk.ee/image/4F0E819F6327AE3E3619551B1A445AE4.jpg
https://r2.xk.ee/image/4F780D43815CDE3C6D09B1E958C18A20.jpg
https://r2.xk.ee/image/05EE656E7E051ADA0D7D9CC14B7F3F69.jpg