Image Optimizer and WebP Converter
收藏资源简介:
Convert, resize, compress, and optimize images on the fly. Dynamically output WebP, JPEG, or PNG formats to speed up web applications.
数据集概述
名称:Image Optimizer and WebP Converter
类别:Media(媒体)
描述:提供动态图像优化服务,可通过简单URL参数实时调整图像尺寸、压缩并转换格式,旨在加速Web应用加载速度。
核心功能
- WebP转换:相比JPEG/PNG,可减少高达70%的图像数据量。
- 智能调整尺寸:自动计算缺失的宽或高以维持原始宽高比,采用高质量的LANCZOS重采样算法。
- 可调质量:支持精细调整图像质量与文件大小之间的平衡,优化加载速度。
- 智能透明度处理:在导出JPEG时自动将带透明通道的图像转为纯RGB,避免格式错误。
- 稳健的图像获取:自动为源URL补充
https://协议,并添加标准User-Agent头以绕过基础抓取限制。
技术详情
- 端点URL:
https://image-optimizer-and-webp-converter.p.rapidapi.com/v1/optimize - 请求方法:GET
- 认证方式:通过RapidAPI网关处理
查询参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
url |
string | 是 | - | 源图像URL;缺少协议时自动添加https:// |
width |
integer | 否 | 原始宽度 | 输出宽度(像素,1-4000) |
height |
integer | 否 | 原始高度 | 输出高度(像素,1-4000) |
format |
string | 否 | webp |
输出格式(webp、jpeg或png) |
quality |
integer | 否 | 80 |
压缩质量(仅JPEG/WebP,范围1-100;PNG忽略) |
提示:若仅提供width或height,API会自动计算另一维度以保持原始宽高比。
错误响应
| HTTP状态码 | 原因 | 说明 |
|---|---|---|
| 400 | 请求错误 | 无法获取图像(源URL不可达或超过10秒超时)、目标文件非有效/受支持的图像格式 |
| 403 | 禁止访问 | 未通过RapidAPI密钥头直接访问API |
| 422 | 无法处理 | 查询参数无效(如宽度超过4000px、质量超出1-100范围) |
使用示例
cURL
curl --request GET --url https://image-optimizer-and-webp-converter.p.rapidapi.com/v1/optimize?url=picsum.photos%2F800%2F600&width=400&format=webp&quality=85 --header X-RapidAPI-Key: YOUR_RAPIDAPI_KEY --header X-RapidAPI-Host: image-optimizer-and-webp-converter.p.rapidapi.com --output optimized_image.webp
JavaScript / Node.js (Fetch)
const url = "https://image-optimizer-and-webp-converter.p.rapidapi.com/v1/optimize?url=https://picsum.photos/800/600&height=300&format=jpeg&quality=90";
const options = { method: GET, headers: { X-RapidAPI-Key: YOUR_RAPIDAPI_KEY, X-RapidAPI-Host: image-optimizer-and-webp-converter.p.rapidapi.com } };
fetch(url, options)
.then(res => {
if (!res.ok) throw new Error(HTTP error! status: ${res.status});
return res.blob();
})
.then(blob => {
const imageUrl = URL.createObjectURL(blob);
console.log("Image ready to use:", imageUrl);
})
.catch(err => console.error(Error fetching image:, err));
Python (Requests)
import requests
url = "https://image-optimizer-and-webp-converter.p.rapidapi.com/v1/optimize" querystring = {"url": "https://picsum.photos/800/600", "width": "500", "format": "png"}
headers = { "X-RapidAPI-Key": "YOUR_RAPIDAPI_KEY", "X-RapidAPI-Host": "image-optimizer-and-webp-converter.p.rapidapi.com" }
response = requests.get(url, headers=headers, params=querystring)
if response.status_code == 200: with open(output.png, wb) as f: f.write(response.content) print("Image successfully saved!") else: print(f"Error: {response.text}")
附加信息
- API创建者:rxmrb699
- 订阅者数:4
- 服务等级:31%
- 平均延迟:147ms
- 流行度:9.3
- 定价:
- BASIC:免费
- PRO:$5.00/月
- ULTRA:$25.00/月



