parallax/jsPDF · error · Error
Width/Height invalid.
Error message
Width/Height invalid.
What it means
Thrown by GifWriter when the canvas width or height is <= 0 or exceeds 65535. GIF stores dimensions as unsigned 16-bit fields, so any value outside 1..65535 for either dimension is invalid before the Logical Screen Descriptor is written.
Source
Thrown at src/libs/omggif.js:42
*
* omggif is a JavaScript implementation of a GIF 89a encoder and decoder,
* including animation and compression. It does not rely on any specific
* underlying system, so should run in the browser, Node, or Plask.
*/
"use strict";
import { console } from "./console.js";
function GifWriter(buf, width, height, gopts) {
var p = 0;
var gopts = gopts === undefined ? {} : gopts;
var loop_count = gopts.loop === undefined ? null : gopts.loop;
var global_palette = gopts.palette === undefined ? null : gopts.palette;
if (width <= 0 || height <= 0 || width > 65535 || height > 65535)
throw new Error("Width/Height invalid.");
function check_palette_and_num_colors(palette) {
var num_colors = palette.length;
if (num_colors < 2 || num_colors > 256 || num_colors & (num_colors - 1)) {
throw new Error(
"Invalid code/color length, must be power of 2 and 2 .. 256."
);
}
return num_colors;
}
// - Header.
buf[p++] = 0x47;
buf[p++] = 0x49;
buf[p++] = 0x46; // GIF
buf[p++] = 0x38;
buf[p++] = 0x39;
buf[p++] = 0x61; // 89aView on GitHub (pinned to a3930ce03a)
Solutions
- Clamp width/height to integers in 1..65535 before constructing GifWriter.
- Ensure the source canvas/image has non-zero natural dimensions.
- Floor any fractional dimension: Math.max(1, Math.floor(w)).
Example fix
// before
var gw = new GifWriter(buf, canvas.width, canvas.height, {});
// after
var w = Math.max(1, Math.min(65535, Math.floor(canvas.width)));
var h = Math.max(1, Math.min(65535, Math.floor(canvas.height)));
var gw = new GifWriter(buf, w, h, {}); Defensive patterns
Strategy: validation
Validate before calling
function validGifDim(d){ d = Math.floor(d); return d >= 1 && d <= 65535 ? d : null; }
var w = validGifDim(width), h = validGifDim(height);
if (w && h) new GifWriter(buf, w, h, gopts); Type guard
function isGifDimension(v){ return Number.isInteger(v) && v >= 1 && v <= 65535; } Try / catch
try { new GifWriter(buf, w, h, gopts); } catch (e) { if (/Width\/Height invalid/.test(e.message)) { /* fix dims */ } else throw e; } Prevention
- Floor fractional canvas dimensions
- Reject zero-size source canvases early
When it happens
Trigger: Calling new GifWriter(buf, width, height, gopts) with width/height of 0, negative, NaN (which fails the <= 0 test), or > 65535. Computing dimensions from a zero-size source canvas; passing undefined which becomes NaN.
Common situations: Generating a GIF from a canvas whose width/height were never set; off-by-one producing 0; upscaling beyond the GIF spec limit; floating-point dimension not floored to an integer.
Related errors
- Invalid code/color length, must be power of 2 and 2 .. 256.
- Background index out of range.
- Background index explicitly passed as 0.
- Loop count invalid.
- x/y invalid.
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/935f09588bdc96ca.
Report an issue: GitHub.