File size: 7,366 Bytes
a4a8647 1ba8490 a4a8647 0b2f2ef a4a8647 1ba8490 a4a8647 0b2f2ef bf310a8 0b2f2ef a4a8647 1ba8490 a4a8647 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef a4a8647 0b2f2ef a4a8647 0b2f2ef a4a8647 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef a4a8647 1ba8490 a4a8647 0b2f2ef a4a8647 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 0b2f2ef 1ba8490 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
---
title: Page Screenshot API
emoji: πΈ
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
license: other
---
# πΈ Page Screenshot API
Professional web page screenshot service built with Node.js and Puppeteer, optimized for Hugging Face Spaces with **full-page support** and **flexible authentication**.
## π Live Demo
- **API Endpoint**: `https://your-username-page-shot.hf.space/screenshot`
- **Demo Interface**: `https://your-username-page-shot.hf.space/demo`
- **Health Check**: `https://your-username-page-shot.hf.space/`
## π Authentication Options
### Option 1: Custom API Key (Recommended)
Set `API_KEY` environment variable in Space settings for secure access:
```bash
# With API key authentication
curl -X POST https://your-space.hf.space/screenshot \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key-here" \
-d '{"url": "https://example.com", "fullPage": true}' \
--output screenshot.jpg
```
### Option 2: Open Access Mode
If no `API_KEY` is set, the API runs in open access mode:
```bash
# Open access (no authentication)
curl -X POST https://your-space.hf.space/screenshot \
-H "Content-Type: application/json" \
-d '{"url": "https://example.com", "width": 1280, "height": 720}' \
--output screenshot.jpg
```
### Option 3: Private Space with HF Token
For private spaces, use HuggingFace access token:
```bash
# Private space access
curl -X POST https://your-space.hf.space/screenshot \
-H "Content-Type: application/json" \
-H "Authorization: Bearer hf_your_token_here" \
-d '{"url": "https://example.com"}' \
--output screenshot.jpg
```
## π API Parameters
| Parameter | Type | Default | Range | Description |
|-----------|------|---------|-------|-------------|
| `url` | string | **required** | - | Target webpage URL (must start with http/https) |
| `width` | number | 1280 | 100-1600 | Screenshot width in pixels |
| `height` | number | 720 | 100-1200 | Screenshot height in pixels |
| `quality` | number | 75 | 10-100 | JPEG quality percentage (JPEG only) |
| `fullPage` | boolean | false | - | **NEW**: Capture full page length (long screenshots) |
| `format` | string | "jpeg" | jpeg/png | **NEW**: Output format (jpeg or png) |
## π New Features in v1.5.0
### π Full Page Screenshots
Capture entire webpage including content below the fold:
```javascript
// Capture full page length
const response = await fetch('/screenshot', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer your-api-key'
},
body: JSON.stringify({
url: 'https://example.com',
fullPage: true, // π Captures entire page height
format: 'png' // π PNG format for better quality
})
});
```
### πΌοΈ Multiple Image Formats
Choose between JPEG (smaller size) and PNG (better quality):
```bash
# PNG format (lossless, larger file)
curl -X POST https://your-space.hf.space/screenshot \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{"url": "https://example.com", "format": "png"}' \
--output screenshot.png
# JPEG format (compressed, smaller file)
curl -X POST https://your-space.hf.space/screenshot \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{"url": "https://example.com", "format": "jpeg", "quality": 85}' \
--output screenshot.jpg
```
## π Response Examples
### Success Response
```
HTTP/1.1 200 OK
Content-Type: image/jpeg # or image/png
Content-Length: 245760
[Binary image data]
```
### Authentication Error
```json
{
"error": "Unauthorized",
"message": "Valid API key required. Please provide API key in Authorization header or x-api-key header.",
"hint": "Use \"Authorization: Bearer YOUR_API_KEY\" or \"x-api-key: YOUR_API_KEY\""
}
```
### Server Busy Response
```json
{
"status": "busy",
"error": "Server is currently overloaded",
"cpuUsage": "96%",
"queueLength": 3
}
```
## π οΈ Features
- β
**Full Page Screenshots** - Capture entire webpage length
- β
**Multiple Formats** - JPEG (compressed) and PNG (lossless) support
- β
**Flexible Authentication** - API key, open access, or HF token
- β
**Global Font Support** - Renders CJK, Arabic, Emoji fonts correctly
- β
**Queue Management** - Handles concurrent requests efficiently
- β
**CPU Monitoring** - Automatic load balancing
- β
**Rate Limiting** - Prevents abuse (100 req/15min)
- β
**Error Handling** - Comprehensive error responses
- β
**Demo Interface** - Built-in testing UI with auth detection
- β
**Health Monitoring** - Status endpoint for monitoring
## π§ Setup Instructions
### Step 1: Configure Authentication (Optional)
```bash
# In HuggingFace Space Settings β Variables
API_KEY=sk-your-secure-random-key-here
```
### Step 2: Deploy to HuggingFace Spaces
1. Create new Space with Docker SDK
2. Upload all files to Space repository
3. Set environment variables if needed
4. Space will auto-deploy
### Step 3: Test the API
Visit the demo page: `https://your-space.hf.space/demo`
## π Monitoring Endpoints
### Health Check
```bash
curl https://your-space.hf.space/
# Returns API info and authentication status
```
### Server Status
```bash
curl https://your-space.hf.space/status
# Returns CPU usage, active requests, queue status
```
## π¨ Rate Limits & Performance
| Metric | Limit | Notes |
|--------|-------|-------|
| Requests | 100/15min | Per IP address |
| Concurrent | 3 requests | Server queue management |
| CPU Threshold | 95% | Auto-rejects when overloaded |
| Timeout | 15 seconds | Per screenshot request |
| Max Dimensions | 1600x1200 | Viewport size limits |
## π Security & License
- **Proprietary License**: Commercial use requires separate license
- **Non-Commercial Use**: Educational and personal use permitted
- **API Security**: Optional API key authentication
- **Resource Protection**: Built-in rate limiting and queue management
## π Global Font Support
Optimized for international websites with support for:
- **CJK Languages**: Chinese, Japanese, Korean
- **RTL Languages**: Arabic, Hebrew
- **Emoji & Symbols**: Full Unicode emoji support
- **Latin Scripts**: European languages with proper rendering
## π‘οΈ Production Recommendations
1. **Enable API Key**: Set `API_KEY` environment variable for production
2. **Use Private Space**: For sensitive or commercial use
3. **Implement Retry Logic**: Handle busy server responses
4. **Monitor Usage**: Use `/status` endpoint for health checks
5. **Choose Format Wisely**: JPEG for photos, PNG for graphics/text
## π Documentation
- [API Authentication Guide](API_GUIDE.md)
- [Private Space Setup](PRIVATE_SPACE_GUIDE.md)
- [Environment Variables](HF_SPACES_ENV_GUIDE.md)
- [Deployment Guide](DEPLOYMENT_GUIDE.md)
## π License
**Proprietary Non-Commercial License** - See [LICENSE](LICENSE) for full terms.
- β
Educational and personal use
- β Commercial use without license
- β Redistribution or modification
## π€ Support
For commercial licensing, technical support, or feature requests, please contact the administrator. |