parallax/jsPDF · error · Error

An unknown error occurred whilst processing the image

Error message

An unknown error occurred whilst processing the image

What it means

getImageProperties() calls the format-specific processor (processPNG, processJPEG, etc.) and checks that the result is truthy. A falsy return means the processor ran but failed to produce a valid image object — typically due to corrupt or incomplete image data that passed format detection. This mirrors the same catch-all guard in processImageData (error [86]) but applies to the getImageProperties path.

Source

Thrown at src/modules/addimage.js:1000

    format = getImageFileTypeByImageData(imageData);
    if (!isImageTypeSupported(format)) {
      throw new Error(
        "addImage does not support files of type '" +
          format +
          "', please ensure that a plugin for '" +
          format +
          "' support is added."
      );
    }

    if (!(imageData instanceof Uint8Array)) {
      imageData = binaryStringToUint8Array(imageData);
    }

    image = this["process" + format.toUpperCase()](imageData);

    if (!image) {
      throw new Error("An unknown error occurred whilst processing the image");
    }

    image.fileType = format;

    return image;
  };
})(jsPDF.API);

View on GitHub (pinned to a3930ce03a)

Solutions

  1. Validate the image data integrity before calling getImageProperties
  2. Try-catch around getImageProperties and fall back to default dimensions if it fails
  3. Re-fetch or re-encode the image from the original source
  4. Use a dedicated image validation library to verify the data structure before passing to jsPDF

Example fix

// before
var props = doc.getImageProperties(possiblyCorruptData); // throws

// after - guard with try-catch and defaults
var props;
try {
  props = doc.getImageProperties(data);
} catch (e) {
  props = { width: 100, height: 100 }; // sensible defaults
}
doc.addImage(data, 'PNG', 10, 10, props.width, props.height);
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-validate image data before calling getImageProperties
function tryGetImageProperties(doc, data, fallback) {
  try {
    return doc.getImageProperties(data);
  } catch (e) {
    console.warn('getImageProperties failed, using fallback:', e.message);
    return fallback || { width: 100, height: 100 };
  }
}

Try / catch

try {
  var props = doc.getImageProperties(imageData);
} catch (e) {
  if (e.message.includes('unknown error occurred whilst processing the image')) {
    // Data is corrupt - use fallback dimensions
    var props = { width: 200, height: 150 };
  } else throw e;
}

Prevention

When it happens

Trigger: Passing image data with valid magic bytes but a corrupt or truncated body. Passing data where the internal structure (IHDR, SOS markers, etc.) is malformed. Memory or processing errors in the image decoder that return without throwing. A format processor bug that returns null on certain valid inputs.

Common situations: Inspecting properties of user-uploaded images that are partially written. Processing images fetched over unreliable connections. Working with images produced by non-standard encoders. Using getImageProperties as a pre-flight check before addImage on untrusted data.

Related errors


AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13). Data as JSON: /api/errors/44d053a833f22902. Report an issue: GitHub.