Skip to content

try mensure image not loaded with sycronous request #21

@RodrigoDornelles

Description

@RodrigoDornelles
function getPngSize(url) {
  const xhr = new XMLHttpRequest();
  xhr.open("GET", url, false);
  xhr.responseType = "arraybuffer";
  xhr.send();

  const d = new DataView(xhr.response);
  if (xhr.status !== 200 || d.getUint32(0) !== 0x89504E47) return null;

  const width = d.getUint32(16, false);
  const height = d.getUint32(20, false);
  return { width, height };
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions