Dash85
Dash85

Reputation: 11

How to get a video poster’s image dimensions?

How to get the image dimensions (width and height) of the poster image in a <video poster="…"> element? jQuery is acceptable.

Upvotes: 1

Views: 369

Answers (1)

Sebastian Simon
Sebastian Simon

Reputation: 19485

If your <video> element is referenced as yourVideo (e.g. const yourVideo = document.querySelector("video");), then you can get its poster URL by the poster property. This is just an image URL, so get its dimensions like with any image URL:

const poster = Object.assign(new Image(), {
    src: yourVideo.poster
  });

poster.addEventListener("load", () => console.log(poster.width, poster.height));

Upvotes: 2

Related Questions