# API

目录

1. [接口列表](#jie-kou-lie-biao)
2. [基本请求参数](#ji-ben-qing-qiu-can-shu)
3. #### [接口详情](#jie-kou-xiang-qing-1)
   1. #### [随机图片文件（Random Anime Image File）\[GET\]接口](#sui-ji-tu-pian-wen-jian-random-anime-image-fileget-jie-kou-1)
   2. #### [随机图片文件 *推荐！*（Random Anime Image FIle *Recommend*）\[GET\]接口](#sui-ji-tu-pian-wen-jian-tui-jian-random-anime-image-file-recommendget-jie-kou-1)
   3. #### [随机图片元信息（Random Anime Image Meta Info）\[POST\]接口](#sui-ji-tu-pian-yuan-xin-xi-random-anime-image-meta-infopost-jie-kou-1)
   4. #### [随机图片元信息（Random Anime Image Meta Info）\[Get\]接口](#sui-ji-tu-pian-yuan-xin-xi-random-anime-image-meta-infoget-jie-kou-1)
   5. [获取现有数据库内的标签（Get Images Tags）](#huo-qu-xian-you-tu-pian-biao-qian)

支持CORS

### 接口列表

接口总表

| 接口名             | 接口地址       | 请求方式  | 接口内容                | 范例           |
| --------------- | ---------- | ----- | ------------------- | ------------ |
| 随机图片文件          | image      | Get   | Image               | /image       |
| 随机图片文件          | image      | Post  | same as images.json |              |
| 随机图片文件 redirect | images     | Get   | Image               | /images      |
| 随机图片元信息         | image      | Ppost | JSon Object         | /images      |
| 随机图片元信息         | image.json | Get   | JSon Object         | /images.json |
| 随机图片元信息         | image.json | Post  | same as images.json |              |
| 获取标签列表          | tags       | Get   |                     |              |

### 基本请求参数

| 参数名       | 数据类型       | 默认值  | 范例               | 说明                                                                                                                      |
| --------- | ---------- | ---- | ---------------- | ----------------------------------------------------------------------------------------------------------------------- |
| nin       | string     |      | boy,long\_hair   | 英文逗号分割,排除的分类 [categories-chang-jian-fen-lei](https://doc.pic.re/usage-shi-yong/categories-chang-jian-fen-lei "mention") |
| in        | string     |      | girl,short\_hair | 同上                                                                                                                      |
| id        | int        |      | 236433           | 图片id,使用此字段之后其他筛选条件将失效                                                                                                   |
| compress  | true/false | true |                  | true则加载webp格式图片，有效提高加载速度                                                                                                |
| mix\_size | int        |      |                  | 默认无最小尺寸限制                                                                                                               |
| max\_size | int        | 6144 |                  | 默认最大不超过6144\*6144，超过该尺寸需要设置此参数                                                                                          |

#### 接口详情

#### 随机图片文件（Random Anime Image File）\[GET]接口&#x20;

| 接口名   | 请求方式 | 接口内容  | 范例     |
| ----- | ---- | ----- | ------ |
| image | GET  | Image | /image |

默认提供https/http，get请求方式，例：

```
curl -I -XGET "https://pic.re/image"
```

除开主要的经随机筛选而来的图片内容外，额外图片信息均储存在`Response Header`中

见响应头,主要可用字段为

```
HTTP/1.1 200 OK
Date: Sat, 15 May 2021 15:01:25 GMT
Content-Type: image/jpeg
Content-Length: 689008
Connection: keep-alive
image_id: 242637
image_source: https://www.pixiv.net/member_illust.php?mode=medium&illust_id=63026388
image_tags: aqua_eyes,armor,fate/extra,fate/extra_ccc,fate/grand_order,fate_(series),long_hair,meltryllis,polychromatic,purple_hair,tagme_(artist)
```

#### 随机图片文件 *推荐！*（Random Anime Image FIle *Recommend*）\[GET]接口

| 接口名    | 请求方式 | 接口内容  | 范例      |
| ------ | ---- | ----- | ------- |
| images | GET  | Image | /images |

参数与`/image`接口通用，区别是会使用301跳转到CDN地址。此接口可以很大的降低服务器压力。

正常访问场景和#1接口无区别

![Example#2](https://pic.re/images)

#### 随机图片元信息（Random Anime Image Meta Info）\[POST]接口

| 接口名   | 请求方式 | 接口内容        | 范例     |
| ----- | ---- | ----------- | ------ |
| image | POST | JSon Object | /image |

默认提供https/http,POST请求方式，例：

```
curl -XPOST "https://pic.re/image"
```

返回Json数据

```
{
    "file_url":"https://konachan.com/image/c2013204d3c186f0b95e433eea9bce15/Konachan.com%20-%20208569%20animal%20aqua_hair%20bird%20boots%20bow%20building%20city%20clouds%20gloves%20hat%20hinanawi_tenshi%20night%20red_eyes%20short_hair%20skirt_lift%20sky%20touhou%20tree%20waira%20water.jpg",
    "md5":"c2013204d3c186f0b95e433eea9bce15",
    "tags":[
        "animal",
        "aqua_hair",
        "bird",
        "boots",
        "bow",
        "building",
        "city",
        "clouds",
        "gloves",
        "hat",
        "hinanawi_tenshi",
        "night",
        "red_eyes",
        "short_hair",
        "skirt_lift",
        "sky",
        "touhou",
        "tree",
        "waira",
        "water"
    ],
    "width":2047,
    "height":1447,
    "source":"http://i4.pixiv.net/img-original/img/2015/10/24/00/31/25/53177335_p0.jpg",
    "author":"Flandre93",
    "has_children":false,
    "_id":208569
}
```

#### 随机图片元信息（Random Anime Image Meta Info）\[Get]接口

| 接口名        | 请求方式 | 接口内容        | 范例           |
| ---------- | ---- | ----------- | ------------ |
| image.json | Get  | JSon Object | /images.json |

同Post接口内容

### 获取现有图片标签

获取现有数据库内大于一定图片量的表情

| 接口名  | 请求方式       | 接口内容        | 范例 |
| ---- | ---------- | ----------- | -- |
| tags | GET & POST | JSon Object |    |

Example：

```
[
    {
        "name": "long_hair",
        "count": 44045
    },
    {
        "name": "original",
        "count": 24985
    },
    {
        "name": "short_hair",
        "count": 19695
    },
    {
        "name": "blush",
        "count": 17494
    }
]
```
