How would I convert a Image ID to a Decal ID?

Title explains it all, I would like to convert a ImageID to a decalID, most say its impossible due to the limited resources roblox provides, and mostly the resources available is just decalID to imageID conversion, which is not what I am aiming for.

Is there any way I could do the opposite (img > dec)? Thanks

2 Likes

I was having the same issue until I found out Roblox had a API for that.

rbxthumb://type=Asset&id=IMAGEID&w=768&h=432

This is the devforum that helped me: New ContentId format for easy thumbnail loading

6 Likes

The above reply will only make the image load, not fetch the decal ID.

A solution to fetching the decal id is brute forcing by taking advantage of the fact that the decal id is the asset id, incremented by a small amount, usually less than 10. Here’s a solution that uses brute force to find the answer:

local MarketplaceService = game:GetService("MarketplaceService")

local assetId = 0
local lookAhead = 10 --check 10 ids ahead

--The type checking is to make your life easier if you want to modify the isTheDecal function
type creator = {CreatorTargetId: number, CreatorType: string, HasVerifiedBadge: boolean, Id: number, Name: string}
type productInfo = {AssetId: number, AssetTypeId: number, ContentRatingTypeId: number, Created: string, 
	Creator: creator, Description: string, IconImageAssetId: number, IsForSale: boolean, IsLimited: boolean, 
	IsLimitedUnique: boolean, IsNew: boolean, IsPublicDomain: boolean, MinimumMembershipLevel: number, 
	Name: string, ProductId: number, ProductType: string, Sales: number, TargetId: number, Updated: string}

local function getInfo(id: number): productInfo?
	local success, response = pcall(function()
		return MarketplaceService:GetProductInfo(id)
	end)
	if success then
		return response
	else
		if response:find("not a valid assetId") then return nil end
		warn(response)
		return getInfo(id)
	end
end

--determines if the decal belongs to that assetId based on assetInfo and decalInfo
local function isTheDecal(assetInfo: productInfo, decalInfo: productInfo): boolean
	local isDecal = (decalInfo.AssetTypeId == 13)
	local sameCreator = (assetInfo.Creator.Id == decalInfo.Creator.Id)
	return isDecal and sameCreator 
end

local function assetToDecalId(assetId: number, lookAhead: number): number?
	local assetInfo = getInfo(assetId)
	if not assetInfo then error(assetId.." is not a valid assetId") end
	for i = 1, lookAhead do
		local decalId = assetId+i
		local decalInfo = getInfo(decalId)
		if decalInfo and isTheDecal(assetInfo, decalInfo) then return decalId end
	end
	return nil
end

print(assetToDecalId(assetId, lookAhead))

PS: This is the reverse of another known method for converting decal id to asset id, where the decal id is decreased by 1 until a match is found.

5 Likes

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