How does Roblox get the size of an image?

So I just saw that Roblox has an image slice editor and they included the Pixel Size of the image. So, I tried looking through the code of the built-in plugin and I still can’t find any answer on how they do it. Any help is appreciated

image

I’m not sure if this is what you need but are you talking about ImageRectSize ?

I’m talking about the Resolution Size of an Image

I apologize but I cant really help you. Have you tried doing research yourself?

Researching it, it seems like its not possible or very easy. Multiple feature requests have been made about it. A Roblox admin said on one that the data is available internally and could easily be made into a feature, but these requests are years old.

I can probably help with this using hacky methods with HTTPService, but what exactly do you want it for?

I was gonna use this to be able to flip imagelabels.

1 Like

So, Roblox doesn’t support this kind of thing natively yet so I made a proxy system for this. The sample code can be found below. It essentially gets the raw image from AssetDelivery and uses some code to get the dimensions and return it. It’s a lot easier than it sounds when you’ve been doing this for a while.

I’m only spoon-feeding the code to you because it’s a lot to explain and I don’t want to give you a stroke trying to figure it out like I did and I’ve been doing this stuff for a while.

-- Source code here: https://glitch.com/edit/#!/rbximage

local httpService = game:GetService("HttpService")
local baseUrl = "https://rbximage.glitch.me"

local getData = function(imageId)
	local success,response = pcall(function()
		local url = ("%s/getimagedata/%s"):format(baseUrl,httpService:UrlEncode(imageId))
		return httpService:GetAsync(url)
	end)
	if(success and response) then
		return true,httpService:JSONDecode(response)
	elseif(not success) then
		return false,{}
	end
end

-- Usage (example):

local success,response = getData("rbxassetid://8300210667") --> if success == false, something went wrong and it won't have dimensions
if success then
	print(response) --> {height = 549,width = 823,type = "PNG",failed = false}
else
	warn("something went wrong >:(")
end

If you have any issues don’t hesitate to reach out to me! Good luck with flipping your image!

10 Likes