🧹 去水印服务测试

🚀 Node.js 版本服务

服务地址: http://localhost:3000

Docker 支持: ✅ | 共用代码库: ✅ | API 兼容: ✅

0
成功次数
0
失败次数
0ms
平均耗时

📁 文件上传去水印

支持格式:JPEG, PNG, WebP(最大10MB)

🔗 URL去水印

🔍 服务健康检查

⚡ 性能测试

📋 API 调用演示

以下是直接调用去水印 API 的代码示例:

🔗 方式一:通过 URL 去水印

// JavaScript 示例
const removeWatermarkByUrl = async (imageUrl) => {
    try {
        const response = await fetch('${window.location.origin}/v1/remove-watermark', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({
                imageUrl: imageUrl
            })
        });

        const result = await response.json();

        if (result.success) {
            console.log('去水印成功!');
            console.log('结果图片URL:', result.resultUrl);
            return result.resultUrl;
        } else {
            console.error('去水印失败:', result.error);
            return null;
        }
    } catch (error) {
        console.error('API 调用失败:', error);
        return null;
    }
};

// 使用示例
removeWatermarkByUrl('https://example.com/image.jpg')
    .then(resultUrl => {
        if (resultUrl) {
            // 显示结果图片
            document.getElementById('result').src = resultUrl;
        }
    });

📁 方式二:通过文件上传去水印

// JavaScript 示例
const removeWatermarkByFile = async (file) => {
    try {
        const formData = new FormData();
        formData.append('image', file);

        const response = await fetch('${window.location.origin}/v1/remove-watermark/upload', {
            method: 'POST',
            body: formData
        });

        const result = await response.json();

        if (result.success) {
            console.log('去水印成功!');
            console.log('结果图片URL:', result.resultUrl);
            return result.resultUrl;
        } else {
            console.error('去水印失败:', result.error);
            return null;
        }
    } catch (error) {
        console.error('API 调用失败:', error);
        return null;
    }
};

// 使用示例 (配合文件输入框)
const fileInput = document.getElementById('fileInput');
fileInput.addEventListener('change', async (event) => {
    const file = event.target.files[0];
    if (file) {
        const resultUrl = await removeWatermarkByFile(file);
        if (resultUrl) {
            // 显示结果图片
            document.getElementById('result').src = resultUrl;
        }
    }
});

🐍 Python 示例

import requests
import json

# 通过 URL 去水印
def remove_watermark_by_url(image_url):
    url = "http://your-server:port/v1/remove-watermark"
    payload = {"imageUrl": image_url}
    headers = {"Content-Type": "application/json"}

    try:
        response = requests.post(url, json=payload, headers=headers)
        result = response.json()

        if result.get('success'):
            print(f"去水印成功!结果URL: {result['resultUrl']}")
            return result['resultUrl']
        else:
            print(f"去水印失败: {result.get('error')}")
            return None
    except Exception as e:
        print(f"API 调用失败: {e}")
        return None

# 通过文件上传去水印
def remove_watermark_by_file(file_path):
    url = "http://your-server:port/v1/remove-watermark/upload"

    try:
        with open(file_path, 'rb') as f:
            files = {'image': f}
            response = requests.post(url, files=files)
            result = response.json()

            if result.get('success'):
                print(f"去水印成功!结果URL: {result['resultUrl']}")
                return result['resultUrl']
            else:
                print(f"去水印失败: {result.get('error')}")
                return None
    except Exception as e:
        print(f"API 调用失败: {e}")
        return None

# 使用示例
result_url = remove_watermark_by_url("https://example.com/image.jpg")
# 或者
result_url = remove_watermark_by_file("/path/to/image.jpg")

📱 cURL 示例

# 通过 URL 去水印
curl -X POST "http://your-server:port/v1/remove-watermark" \
  -H "Content-Type: application/json" \
  -d '{"imageUrl": "https://example.com/image.jpg"}'

# 通过文件上传去水印
curl -X POST "http://your-server:port/v1/remove-watermark/upload" \
  -F "image=@/path/to/image.jpg"

📊 API 响应格式

// 成功响应
{
    "success": true,
    "resultUrl": "https://api.watermarkremover.io/result/xxx.jpg",
    "taskId": "task_xxx",
    "processTime": 1500,
    "message": "去水印处理完成"
}

// 失败响应
{
    "success": false,
    "error": "图片格式不支持",
    "code": "INVALID_FORMAT",
    "message": "仅支持 JPEG, PNG, WebP 格式"
}