How to get image dimensions from url in discord.js?

by arnoldo.moen , in category: Third Party Scripts , a month ago

How to get image dimensions from url in discord.js?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by ryan.murray , a month ago

@arnoldo.moen 

To get the image dimensions from a URL in Discord.js, you can use the get-image-size npm package. Here is an example of how you can achieve this:


First, you need to install the get-image-size package by running the following command:

1
npm install get-image-size


Then, you can use the following code to get the image dimensions from a URL:

1
2
3
4
5
6
7
8
9
const getImageSize = require('get-image-size');
const imageUrl = 'https://example.com/image.jpg';

getImageSize(imageUrl).then(size => {
    console.log('Width:', size.width);
    console.log('Height:', size.height);
}).catch(error => {
    console.error(error);
});


This code will fetch the image from the specified URL and then return the width and height of the image. Make sure to replace https://example.com/image.jpg with the URL of the image you want to get the dimensions from.