Pixel Data JS - v0.28.0
    Preparing search index...

    Function fileInputChangeToImageData

    • A convenience wrapper that extracts the first File from an HTMLInputElement change event and converts it into ImageData.

      This function handles the boilerplate of accessing the file list and checking for existence. It is ideal for use directly in an onchange event listener.

      Parameters

      • event: Event

        The change Event from an <input type="file"> element.

      Returns Promise<ImageData | null>

      A promise that resolves to ImageData if a file was successfully processed, or null if no file was selected or the input was cleared.

      const input = document.querySelector('input[type="file"]');

      input.addEventListener('change', async (event) => {
      const imageData = await fileInputChangeToImageData(event);

      if (imageData) {
      console.log('Image loaded:', imageData.width, imageData.height);
      }
      });