- Home
- Skills
- APIs & Backend
- Bounded Image Intake Preflight (Node + Python)
Bounded Image Intake Preflight (Node + Python)
Image decoders size their output from the header, not from the file.
$29
Works with the AI Agents you already use
Bounded Image Intake Preflight (Node + Python)
Example session with this skill installed
I need to validate a user-uploaded PNG in a Node.js API to make sure it is not an animated PNG and does not exceed 1080p dimensions before I process it.
- Read your context and instructions
- Compiled the bounded image intake
I have implemented the preflight check using the provided ESM module. This logic sniffs the PNG header and the acTL chunk (for APNG detection) before any pixel buffer is allocated.
Node.js Preflight Implementation
import { preflightImage } from './scripts/image-preflight.mjs';
const limits = {
maxBytes: 5 * 1024 * 1024, // 5MB
minEdge: 10,
maxEdge: 1920,
maxPixels: 2073600, // 1080p
allowAnimated: false
};
try {
const info = preflightImage(uploadBuffer, limits);
console.log('Image accepted:', info);
// Proceed to Sharp/Canvas decoder
} catch (err) {
if (err.code === 'ANIMATED_IMAGE_UNSUPPORTED') {
// Return 400: Animated images not allowed
} else if (err.code === 'INVALID_IMAGE_DIMENSIONS') {
// Return 400: Image exceeds 1080p
}
console.error(`Refused: ${err.code} - ${err.message}`);
}
Next steps
- Copy
scripts/image-preflight.mjsinto your project's utility folder. - Update your Express or Fastify error handler to map
INVALID_IMAGE_DIMENSIONSto an HTTP 400 status. - Run the provided test suite with
node --test scripts/preflight.test.mjsto verify your environment.
Connects securely to your tools. The creator never sees your data.
About this skill
Image decoders size their output from the header, not from the file. A 300-byte PNG that claims 60,000 x 60,000 pixels asks for about 14 GB; an animated WebP multiplies that by its frame count. Any service that hands uploads straight to a decoder can be stalled by a trivial request.
Preflight (image-preflight.mjs, image_preflight.py): reads only the header to learn format and dimensions: PNG IHDR with APNG acTL detection; JPEG marker walk to the first start-of-frame (baseline, extended, progressive, lossless, arithmetic) skipping fill bytes and standalone markers; WebP VP8X (animation flag), VP8 and VP8L. Enforces maxBytes, minEdge, maxEdge, maxPixels and allowAnimated with the codes INVALID_IMAGE_FORMAT, INVALID_IMAGE_DIMENSIONS, ANIMATED_IMAGE_UNSUPPORTED, IMAGE_TOO_LARGE. Same behavior in both languages; both have a CLI that prints one JSON line per file and exits 1 on any refusal.
Binary frame (binary-frame.mjs): one body carries a JSON metadata object and 1 to N binary parts behind a fixed header (magic, part count, metadata length, one 32-bit length per part). The decoder checks every length against your ceilings, requires the lengths to sum to the body exactly, and returns zero-copy views. maxFrameBytes(limits) gives the body ceiling for the route and the reverse proxy.
Tests: 5 Node tests (all formats, animation, truncation, a lying SOF length, ceilings, frame round trip and nine malformed frames, Node/Python CLI agreement) and 3 Python tests, with synthetic header fixtures you can reuse. reference/limits.md explains each default and how to tune it from your memory budget.
Node 20+ or Python 3.10+, no packages, no network.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.
Supports PNG, JPEG, and WebP only. Refuses GIF, HEIC, AVIF, and SVG. Does not apply EXIF orientation. Memory-safe for headers only; decoders still need error handling for pixel data.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 17 days ago
- Software
Node.js 20+
orPython 3.10+