Skip to main content

Access image dimensions of assets in JavaScript

Below you can find an example of how to extract the width and height of one image URL provided by a Storyblok asset URL.

let url = "//"

console.log(url.split('/')[4], 4) // space id
console.log(url.split('/')[5], 5) // dimension string
console.log(url.split('/')[5].split('x')) // width and height as array

let dimensions = {
  width: url.split('/')[5].split('x')[0],
  height: url.split('/')[5].split('x')[1]