0

I need to get the height and width from the end of a url BEFORE LOADING THE IMG. The url I have looks like this:

https://images.or/domain/hiddenuid_2021_logo.webp?auto=compress,format&rect=0,0,350,400&w=350&h=400

As you can see both width and height are represented by w=350 and h=400

I am using React/Nextjs.

Once I can get the height and width, I will then display it in the container as follows:

<Image src={image.url} width={width} height={height} /> 

What is the easiest way to accomplish this?

RandomDeveloper
  • 833
  • 2
  • 9
  • 31

1 Answers1

-1

I found a answer with almost same question:

var url_string = "https://images.or/domain/hiddenuid_2021_logo.webp?auto=compress,format&rect=0,0,350,400&w=350&h=400"; 
var url = new URL(url_string);
var width = url.searchParams.get("w");
var height = url.searchParams.get("h");

alert("Width is: " + width)

alert("Height is: " + height)
BladeOfLightX
  • 504
  • 4
  • 17