Get image size from any image on the catalog

I want to load an image from the catalog and display it with its original aspect ratio.

I initially tried:

game:GetService("MarketplaceService"):GetProductInfo(id)

However, it doesn’t return an aspect ratio nor the dimensions of the image.

I then tried making an ImageLabel, with ScaleType to Crop, and setting AutomaticSize to XY.

After that didn’t work, I looked here, but I couldn’t find anything.

At this point I am open to any answer, even if it includes using an API, preferably with JS, but again, any answer with any coding language would be appreciated.

1 Like

Maybe this post could help:

What I am trying to achieve is the actual size of the original image, not the size of it in game, if that makes sense.

Ohh I see what you’re saying. Honestly I’m not too sure because I looked through JSone functions and couldn’t find any that would match what you are looking for.

1 Like

I know the solution! It will only work if the image is PNG, You can just use the PNG library Module here: MaximumADHD/Roblox-PNG-Library: An implementation of the PNG file format in Lua, natively designed for Roblox. (github.com)
First, You need to get binary from the PNG image, to get the binary of the PNG image, you have to use HttpService and make an “GET” request to “https://assetdelivery.roblox.com/v1/asset?id=(image id here)” and then you do require(the module).new(the binary) and then it will return a table, so you can get the Size like this, Vector2.new((the returned table from the module).Width, (the returned table from the module).Height)

1 Like

Thanks for your response, and this may seem obvious but how do I require the library?

When you go to the github link I sent, you will see PNG.rbxm you must insert it inside Studio.

1 Like

So I downloaded the raw file, how do I insert it into studio?

Right Click on Workspace in explorer, Then click Insert from file, and choose the downloaded raw file.

1 Like

I keep getting this error:

HttpService is not allowed to access ROBLOX resources

Actually do “https://assetdelivery.roproxy.com/v1/asset?id=(image id here)”

2 Likes

Thank you for this solution I was looking everywhere for it, I find it really weird however that ROBLOX doesn’t have a built-in function or behavior for image size.

EDIT: I realized that the library also had pixel data, which was something that I wanted, so I just wanted to thank you again!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.