IntelInlet
Studio journal
Private media tools / / 3 min read

Batch-compress WebP screenshots and add a mockup frame locally

Calculate the content rectangle first, then check fine type, alpha edges and the MIME type of each export.

A delivery requires 1,200-pixel-wide previews with 64 pixels on either side. That leaves 1,072 pixels for the screenshot. Start with a dense table, a photo and a panel with a transparent shadow. They expose different failures at the same quality setting.

Procedure

  1. Use dimensions after orientation correction. A 1,600 × 900 image scaled to 1,072 pixels wide becomes 603 pixels high after rounding. Paint the background, frame and title bar, then draw the screenshot in the content rectangle. Keep the unframed original.

  2. Decode one image at a time. Call canvas.toBlob with a callback, ‘image/webp’ and quality 0.82. Check that the returned Blob exists and its MIME is image/webp before giving it a WebP suffix. Unsupported encoders can fall back to PNG.

  3. Compare sample exports at 0.72, 0.82 and 0.92. Record bytes and intended display size and examine colored fringes around small type. If the budget remains tight, try a smaller output resolution before lowering quality again.

A single-file renderer with fixed margins

Pass one screenshot File to this function. The header gets 48 pixels, the bottom gets 32, and canvas height follows the screenshot. For a batch, await each file in a for…of loop and save the returned Blob before continuing.

async function framedWebP(file) {
  const image = await createImageBitmap(file);
  try {
    const h = Math.round(image.height * 1072 / image.width);
    const canvas = document.createElement("canvas");
    canvas.width = 1200; canvas.height = h + 80;
    const ctx = canvas.getContext("2d");
    ctx.fillStyle = "#f3efe6";
    ctx.fillRect(0, 0, canvas.width, canvas.height);
    ctx.fillStyle = "#353d3b";
    ctx.fillRect(64, 24, 1072, 24);
    ctx.drawImage(image, 64, 48, 1072, h);
    const blob = await new Promise(ok => canvas.toBlob(ok, "image/webp", 0.82));
    if (!blob || blob.type !== "image/webp") throw new Error("WebP unavailable");
    return blob;
  } finally {
    image.close();
  }
}

With the 1,600 × 900 fixture, expect 1,200 × 683. Repeat with a portrait image; the side margins should still be 64 pixels and the content should retain its proportions.

Choosing an approach

Sample First choice Inspect
Small UI text Adequate resolution or lossless Broken strokes and halos
Photo Lossy WebP Banding in shadows
Transparent shadow Preserve alpha Edges over light and dark

Check the result

Place the framed preview over two backgrounds. Check equal margins and ensure the title bar leaves the application menu visible. Give each output a unique name and log source name, dimensions and byte count. Dispose of each decoded bitmap before opening the next.

For a matching tab icon, run the 16-pixel favicon check on the brand mark.

Frequently asked questions

Should I frame a screenshot that already includes browser chrome?

Crop to the content area or use a frameless template. Two title bars consume valuable reading space.

Does changing the extension convert a PNG?

The bytes retain their original encoding. Inspect the Blob MIME or decoded file information before choosing a suffix.

References

Related reading

Private media toolbox ↗