Generate Website Thumbnails On Demand
A website thumbnail is a small-scale screenshot of a web page, typically used as a visual preview in link management tools, bookmark applications, browser history UIs, and website gallery pages. SnapAPI generates thumbnails from any URL by capturing a full-resolution screenshot and resizing it to your specified dimensions in the same API call. The thumb_width parameter accepts a pixel value and scales the screenshot to that width while preserving the aspect ratio, eliminating the need for a separate image resizing step. For square thumbnails used in grid layouts, capture at a fixed viewport width and height, then resize to your target thumbnail dimension.
# Python: generate a 400px wide thumbnail
import requests
resp = requests.get(
"https://api.snapapi.pics/screenshot",
params={
"url": "https://github.com/trending",
"format": "jpeg",
"viewport_width": 1280,
"viewport_height": 800,
"thumb_width": 400,
},
headers={"Authorization": "Bearer YOUR_API_KEY"}
)
open("thumbnail.jpg", "wb").write(resp.content)
print(f"Thumbnail: {len(resp.content):,} bytes")
// Node.js: batch thumbnail generation
const apiKey = process.env.SNAPAPI_KEY;
async function thumbnail(url, width = 400) {
const params = new URLSearchParams({
url,
format: 'jpeg',
viewport_width: '1280',
viewport_height: '800',
thumb_width: String(width),
});
const resp = await fetch(
`https://api.snapapi.pics/screenshot?${params}`,
{ headers: { Authorization: `Bearer ${apiKey}` } }
);
if (!resp.ok) throw new Error(`Thumbnail failed: ${resp.status}`);
return Buffer.from(await resp.arrayBuffer());
}
// Generate thumbnails for a list of URLs
const urls = ['https://example.com', 'https://github.com', 'https://vercel.com'];
const thumbnails = await Promise.all(urls.map(u => thumbnail(u)));
thumbnails.forEach((t, i) => require('fs').writeFileSync(`thumb_${i}.jpg`, t));
Thumbnail Sizes for Common Use Cases
Different use cases call for different thumbnail dimensions. Link preview cards in chat applications typically use thumbnails around 400x250 pixels, which fits well in message thread layouts without dominating the visible area. Browser bookmarks and history grids often use square thumbnails at 200x200 or 300x300 pixels. Website gallery and directory pages use larger thumbnails around 600x400 pixels to give visitors enough detail to recognize the page content at a glance. Social media preview thumbnails at 1200x630 pixels are the standard for OG images shared on Twitter and LinkedIn. Video platform-style cards use a 16:9 aspect ratio at various resolutions. SnapAPI's thumb_width and viewport parameters give you full control over the output size without requiring a separate image processing pipeline. Generate the thumbnail at the exact size your UI needs to avoid client-side rescaling artifacts.
Thumbnail Storage and CDN Delivery
Thumbnails should be generated once per URL and stored in a CDN-backed storage service rather than regenerated on every request. When a new URL is added to your application, enqueue a thumbnail generation job that calls SnapAPI, stores the result in S3, and updates the database record with the CDN URL. Serve thumbnails from CloudFront, Fastly, or Cloudflare CDN with long cache headers rather than proxying through your application server. This architecture eliminates per-request API calls for thumbnail display, serves thumbnails from a globally distributed CDN for low latency, and decouples thumbnail generation timing from the request path. For applications with high URL turnover where thumbnails become stale, implement a background refresh job that recaptures thumbnails older than your configured staleness threshold. For most use cases, a one-week or one-month refresh interval is appropriate since most web pages do not change significantly enough in that period to warrant more frequent thumbnail regeneration.
Handling Thumbnail Generation Failures
Thumbnail generation fails more often than screenshot generation for general URL-based screenshots because thumbnails are typically generated for URLs submitted by users, which includes a higher proportion of broken links, private pages, authentication-required pages, and pages with aggressive bot detection. Design your thumbnail generation system to handle failures gracefully. On API error, store a failure record in the database and use a generic placeholder thumbnail in the UI rather than showing a broken image. Retry failed thumbnails after a configurable delay: some failures are transient (network error, temporary rate limiting) while others are permanent (private page, bot-blocked domain). After three failed attempts with exponential backoff, mark the URL as permanently failed and stop retrying to avoid wasting API quota on URLs that will never produce a successful thumbnail. For particularly high-value URLs where a placeholder thumbnail is unacceptable, implement a fallback to favicon-based minimal previews: fetch the favicon from the target domain and display it in a styled frame as the thumbnail, which provides some visual differentiation while the actual screenshot fails.
Thumbnail API Pricing
Thumbnail generation uses the same request quota as any other screenshot request. Each thumbnail generation call consumes one request from your monthly quota, regardless of the output size or format. The thumb_width parameter does not cost extra compared to a full-resolution screenshot. For applications that generate thumbnails for user-submitted URLs, the monthly request count equals the number of unique URLs for which thumbnails are generated during that month, assuming proper caching and deduplication. The free tier at 200 requests per month is sufficient to build a thumbnail generation prototype and test it against your real URL data before upgrading. The Starter plan at 19 dollars per month and 5,000 requests supports a bookmark or link management application adding up to 160 new unique URLs per day. The Growth plan at 79 dollars per month and 50,000 requests supports up to 1,600 new URLs per day. Custom enterprise plans are available for applications with higher thumbnail generation volume.