pexels-media
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePexels Media Sourcing
Pexels媒体资源获取
Source high-quality, royalty-free images and videos from Pexels for design work, placeholders, or content creation.
从Pexels获取高质量、可免费商用的图片和视频,用于设计工作、占位符或内容创作。
Prerequisites
前置条件
This skill requires the environment variable to be set.
PEXELS_API_KEYbash
undefined使用本技能需要设置环境变量。
PEXELS_API_KEYbash
undefinedCheck if API key is available
检查API密钥是否可用
echo $PEXELS_API_KEY
If not set, obtain a free API key from [Pexels API](https://www.pexels.com/api/).echo $PEXELS_API_KEY
如果未设置,请从[Pexels API](https://www.pexels.com/api/)获取免费API密钥。API Base URLs
API基础地址
- Photos:
https://api.pexels.com/v1/ - Videos:
https://api.pexels.com/videos/
- 图片:
https://api.pexels.com/v1/ - 视频:
https://api.pexels.com/videos/
Authentication
身份验证
All requests require the Authorization header:
bash
curl -H "Authorization: $PEXELS_API_KEY" "https://api.pexels.com/v1/search?query=nature"所有请求都需要携带Authorization请求头:
bash
curl -H "Authorization: $PEXELS_API_KEY" "https://api.pexels.com/v1/search?query=nature"Photo Endpoints
图片接口
Search Photos
搜索图片
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/search?query=QUERY&orientation=ORIENTATION&size=SIZE&color=COLOR&locale=LOCALE&page=PAGE&per_page=PER_PAGE"Parameters:
| Parameter | Required | Values |
|---|---|---|
| Yes | Search term |
| No | |
| No | |
| No | |
| No | |
| No | Page number (default: 1) |
| No | Results per page (default: 15, max: 80) |
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/search?query=QUERY&orientation=ORIENTATION&size=SIZE&color=COLOR&locale=LOCALE&page=PAGE&per_page=PER_PAGE"参数说明:
| 参数 | 是否必填 | 可选值 |
|---|---|---|
| 是 | 搜索关键词 |
| 否 | |
| 否 | |
| 否 | |
| 否 | |
| 否 | 页码(默认:1) |
| 否 | 每页结果数量(默认:15,最大值:80) |
Curated Photos
精选图片
Trending photos curated by the Pexels team (updated hourly):
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/curated?page=1&per_page=15"由Pexels团队精选的热门图片(每小时更新):
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/curated?page=1&per_page=15"Get Photo by ID
通过ID获取图片
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/photos/PHOTO_ID"bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/photos/PHOTO_ID"Video Endpoints
视频接口
Search Videos
搜索视频
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/videos/search?query=QUERY&orientation=ORIENTATION&size=SIZE&min_width=MIN_WIDTH&min_height=MIN_HEIGHT&min_duration=MIN_DURATION&max_duration=MAX_DURATION&page=PAGE&per_page=PER_PAGE"Additional Video Parameters:
| Parameter | Description |
|---|---|
| Minimum width in pixels |
| Minimum height in pixels |
| Minimum duration in seconds |
| Maximum duration in seconds |
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/videos/search?query=QUERY&orientation=ORIENTATION&size=SIZE&min_width=MIN_WIDTH&min_height=MIN_HEIGHT&min_duration=MIN_DURATION&max_duration=MAX_DURATION&page=PAGE&per_page=PER_PAGE"视频额外参数:
| 参数 | 说明 |
|---|---|
| 最小宽度(像素) |
| 最小高度(像素) |
| 最小时长(秒) |
| 最大时长(秒) |
Popular Videos
热门视频
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/videos/popular?min_width=1920&min_duration=10&max_duration=60&page=1&per_page=15"bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/videos/popular?min_width=1920&min_duration=10&max_duration=60&page=1&per_page=15"Get Video by ID
通过ID获取视频
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/videos/videos/VIDEO_ID"bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/videos/videos/VIDEO_ID"Collections
合集
Featured Collections
精选合集
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/collections/featured?page=1&per_page=15"bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/collections/featured?page=1&per_page=15"Collection Media
合集中的媒体资源
bash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/collections/COLLECTION_ID?type=TYPE&page=1&per_page=15"Type parameter: , , or omit for both.
photosvideosbash
curl -H "Authorization: $PEXELS_API_KEY" \
"https://api.pexels.com/v1/collections/COLLECTION_ID?type=TYPE&page=1&per_page=15"Type参数: (图片), (视频),或留空同时获取两者。
photosvideosPhoto Sizes Available
可用的图片尺寸
When downloading photos, these sizes are available in the API response:
| Key | Description |
|---|---|
| Original size uploaded by photographer |
| Width 940px, height doubled |
| Width 940px |
| Height 350px |
| Height 130px |
| Width 800px, height 1200px |
| Width 1200px, height 627px |
| Width 280px, height 200px |
下载图片时,API响应中会提供以下尺寸选项:
| 键名 | 说明 |
|---|---|
| 摄影师上传的原始尺寸 |
| 宽度940px,高度翻倍 |
| 宽度940px |
| 高度350px |
| 高度130px |
| 宽度800px,高度1200px |
| 宽度1200px,高度627px |
| 宽度280px,高度200px |
Video Files Available
可用的视频文件
Videos include multiple quality files in the response:
| Quality | Typical Resolution |
|---|---|
| 1280x720 |
| 640x360 |
| Adaptive streaming |
| Various | Full HD, 4K when available |
视频响应中包含多种画质的文件:
| 画质 | 典型分辨率 |
|---|---|
| 1280x720 |
| 640x360 |
| 自适应流 |
| 其他 | 支持全高清、4K(如有提供) |
MANDATORY: Sidecar Metadata Files
强制要求:附属元数据文件
CRITICAL REQUIREMENT: For EVERY downloaded file, you MUST create a sidecar metadata file.
关键要求: 对于每个下载的文件,必须创建一个附属元数据文件。
Sidecar File Naming
附属文件命名规则
For a downloaded file , create .
mountain-sunset.jpgmountain-sunset.jpg.meta.json如果下载的文件名为,则创建。
mountain-sunset.jpgmountain-sunset.jpg.meta.jsonPhoto Sidecar Content
图片附属文件内容
json
{
"source": "pexels",
"type": "photo",
"id": 12345,
"url": "https://www.pexels.com/photo/12345/",
"download_url": "https://images.pexels.com/photos/12345/pexels-photo-12345.jpeg",
"downloaded_size": "large",
"width": 1920,
"height": 1080,
"photographer": "John Doe",
"photographer_url": "https://www.pexels.com/@johndoe",
"photographer_id": 67890,
"avg_color": "#7E5835",
"alt": "Brown mountain during sunset",
"license": "Pexels License - Free for personal and commercial use",
"attribution": "Photo by John Doe on Pexels",
"attribution_html": "<a href=\"https://www.pexels.com/photo/12345/\">Photo</a> by <a href=\"https://www.pexels.com/@johndoe\">John Doe</a> on <a href=\"https://www.pexels.com\">Pexels</a>",
"downloaded_at": "2025-12-02T14:30:00Z",
"api_response": {
// Full original API response for this photo
}
}json
{
"source": "pexels",
"type": "photo",
"id": 12345,
"url": "https://www.pexels.com/photo/12345/",
"download_url": "https://images.pexels.com/photos/12345/pexels-photo-12345.jpeg",
"downloaded_size": "large",
"width": 1920,
"height": 1080,
"photographer": "John Doe",
"photographer_url": "https://www.pexels.com/@johndoe",
"photographer_id": 67890,
"avg_color": "#7E5835",
"alt": "Brown mountain during sunset",
"license": "Pexels License - Free for personal and commercial use",
"attribution": "Photo by John Doe on Pexels",
"attribution_html": "<a href=\"https://www.pexels.com/photo/12345/\">Photo</a> by <a href=\"https://www.pexels.com/@johndoe\">John Doe</a> on <a href=\"https://www.pexels.com\">Pexels</a>",
"downloaded_at": "2025-12-02T14:30:00Z",
"api_response": {
// 该图片的完整原始API响应内容
}
}Video Sidecar Content
视频附属文件内容
json
{
"source": "pexels",
"type": "video",
"id": 12345,
"url": "https://www.pexels.com/video/12345/",
"download_url": "https://videos.pexels.com/video-files/12345/...",
"downloaded_quality": "hd",
"width": 1920,
"height": 1080,
"duration": 30,
"user": {
"id": 67890,
"name": "John Doe",
"url": "https://www.pexels.com/@johndoe"
},
"video_files": [
{
"id": 1,
"quality": "hd",
"file_type": "video/mp4",
"width": 1920,
"height": 1080,
"link": "https://..."
}
],
"video_pictures": [
{
"id": 1,
"picture": "https://...",
"nr": 0
}
],
"license": "Pexels License - Free for personal and commercial use",
"attribution": "Video by John Doe on Pexels",
"downloaded_at": "2025-12-02T14:30:00Z",
"api_response": {
// Full original API response for this video
}
}json
{
"source": "pexels",
"type": "video",
"id": 12345,
"url": "https://www.pexels.com/video/12345/",
"download_url": "https://videos.pexels.com/video-files/12345/...",
"downloaded_quality": "hd",
"width": 1920,
"height": 1080,
"duration": 30,
"user": {
"id": 67890,
"name": "John Doe",
"url": "https://www.pexels.com/@johndoe"
},
"video_files": [
{
"id": 1,
"quality": "hd",
"file_type": "video/mp4",
"width": 1920,
"height": 1080,
"link": "https://..."
}
],
"video_pictures": [
{
"id": 1,
"picture": "https://...",
"nr": 0
}
],
"license": "Pexels License - Free for personal and commercial use",
"attribution": "Video by John Doe on Pexels",
"downloaded_at": "2025-12-02T14:30:00Z",
"api_response": {
// 该视频的完整原始API响应内容
}
}Download Workflow
下载工作流
1. Search and Select
1. 搜索并选择资源
bash
undefinedbash
undefinedSearch for photos
搜索图片
RESPONSE=$(curl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/search?query=office+workspace&orientation=landscape&per_page=5")
"https://api.pexels.com/v1/search?query=office+workspace&orientation=landscape&per_page=5")
RESPONSE=$(curl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/search?query=office+workspace&orientation=landscape&per_page=5")
"https://api.pexels.com/v1/search?query=office+workspace&orientation=landscape&per_page=5")
Parse and display results
解析并显示结果
echo "$RESPONSE" | jq '.photos[] | {id, photographer, alt, url: .src.large}'
undefinedecho "$RESPONSE" | jq '.photos[] | {id, photographer, alt, url: .src.large}'
undefined2. Download with Sidecar
2. 下载并生成附属文件
bash
undefinedbash
undefinedGet photo details
获取图片详情
PHOTO_ID=12345
PHOTO_DATA=$(curl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/photos/$PHOTO_ID")
"https://api.pexels.com/v1/photos/$PHOTO_ID")
PHOTO_ID=12345
PHOTO_DATA=$(curl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/photos/$PHOTO_ID")
"https://api.pexels.com/v1/photos/$PHOTO_ID")
Extract download URL (choose size)
提取下载地址(选择尺寸)
DOWNLOAD_URL=$(echo "$PHOTO_DATA" | jq -r '.src.large')
FILENAME="pexels-$PHOTO_ID-large.jpg"
DOWNLOAD_URL=$(echo "$PHOTO_DATA" | jq -r '.src.large')
FILENAME="pexels-$PHOTO_ID-large.jpg"
Download the image
下载图片
curl -L -o "$FILENAME" "$DOWNLOAD_URL"
curl -L -o "$FILENAME" "$DOWNLOAD_URL"
Create sidecar metadata (MANDATORY)
创建附属元数据文件(强制要求)
echo "$PHOTO_DATA" | jq '{
source: "pexels",
type: "photo",
id: .id,
url: .url,
download_url: .src.large,
downloaded_size: "large",
width: .width,
height: .height,
photographer: .photographer,
photographer_url: .photographer_url,
photographer_id: .photographer_id,
avg_color: .avg_color,
alt: .alt,
license: "Pexels License - Free for personal and commercial use",
attribution: ("Photo by " + .photographer + " on Pexels"),
downloaded_at: (now | todate),
api_response: .
}' > "$FILENAME.meta.json"
undefinedecho "$PHOTO_DATA" | jq '{
source: "pexels",
type: "photo",
id: .id,
url: .url,
download_url: .src.large,
downloaded_size: "large",
width: .width,
height: .height,
photographer: .photographer,
photographer_url: .photographer_url,
photographer_id: .photographer_id,
avg_color: .avg_color,
alt: .alt,
license: "Pexels License - Free for personal and commercial use",
attribution: ("Photo by " + .photographer + " on Pexels"),
downloaded_at: (now | todate),
api_response: .
}' > "$FILENAME.meta.json"
undefinedRate Limits
请求频率限制
- Default: 200 requests/hour, 20,000 requests/month
- Check response headers for current limits:
X-Ratelimit-LimitX-Ratelimit-RemainingX-Ratelimit-Reset
- 默认限制: 每小时200次请求,每月20000次请求
- 可通过响应头查看当前限制:
X-Ratelimit-LimitX-Ratelimit-RemainingX-Ratelimit-Reset
Attribution Best Practices
署名最佳实践
While not legally required by the Pexels license, attribution is encouraged:
- Minimal: "Photo by [Photographer] on Pexels"
- With link: "Photo by Photographer on Pexels"
- HTML: Use the from the sidecar file
attribution_html
虽然Pexels许可证没有强制要求署名,但建议进行署名:
- 最简形式: "Photo by [摄影师姓名] on Pexels"
- 带链接形式: "Photo by 摄影师姓名 on Pexels"
- HTML格式: 使用附属文件中的内容
attribution_html
Example Use Cases
示例用例
Placeholder Images for UI Design
UI设计占位符图片
bash
undefinedbash
undefinedGet 5 abstract/minimal images for placeholders
获取5张抽象/极简风格的占位符图片
curl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/search?query=minimal+abstract&orientation=square&size=small&per_page=5"
"https://api.pexels.com/v1/search?query=minimal+abstract&orientation=square&size=small&per_page=5"
undefinedcurl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/search?query=minimal+abstract&orientation=square&size=small&per_page=5"
"https://api.pexels.com/v1/search?query=minimal+abstract&orientation=square&size=small&per_page=5"
undefinedHero Background Video
首页背景视频
bash
undefinedbash
undefinedFind short, wide landscape videos
查找短时长、宽屏的风景视频
curl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/videos/search?query=nature+aerial&orientation=landscape&min_width=1920&min_duration=5&max_duration=15"
"https://api.pexels.com/videos/search?query=nature+aerial&orientation=landscape&min_width=1920&min_duration=5&max_duration=15"
undefinedcurl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/videos/search?query=nature+aerial&orientation=landscape&min_width=1920&min_duration=5&max_duration=15"
"https://api.pexels.com/videos/search?query=nature+aerial&orientation=landscape&min_width=1920&min_duration=5&max_duration=15"
undefinedProduct Photography Backgrounds
产品摄影背景
bash
undefinedbash
undefinedSearch for clean, neutral backgrounds
搜索干净、中性的背景
curl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/search?query=white+background+texture&color=white&size=large"
"https://api.pexels.com/v1/search?query=white+background+texture&color=white&size=large"
undefinedcurl -s -H "Authorization: $PEXELS_API_KEY"
"https://api.pexels.com/v1/search?query=white+background+texture&color=white&size=large"
"https://api.pexels.com/v1/search?query=white+background+texture&color=white&size=large"
undefinedChecklist
检查清单
When using this skill:
- Verify is set
PEXELS_API_KEY - Choose appropriate endpoint (search, curated, popular, collection)
- Apply relevant filters (orientation, size, color, duration)
- Select appropriate resolution for use case
- Download file to appropriate location
- CREATE SIDECAR METADATA FILE (mandatory)
- Consider attribution in final use
使用本技能时,请确认:
- 已验证已设置
PEXELS_API_KEY - 选择了合适的接口(搜索、精选、热门、合集)
- 应用了相关筛选条件(方向、尺寸、颜色、时长)
- 为使用场景选择了合适的分辨率
- 将文件下载到了合适的位置
- 已创建附属元数据文件(强制要求)
- 在最终使用中考虑了署名