ID:159868
 
How would I make a proc to return image dimensions? I've tried some things, but none have worked. Any help?
I suppose you could use the icon_states() proc and then do some math to determine the size based on what it returns. It'll return a list of icon states and coordinates as x,y for all the states in the image then you'll have to figure it out based on those. The only problem arises if dimensions aren't in multiples of 32.
You can't currently, in BYOND.
This was bugging me so I sussed out some code. It's not robust and hardly thoroughly tested, but it's a place to start:
proc/image_dimension(icon/I)
if(!I)return

var/list/S = icon_states(I)
//Grab the top right icon_state
var/TR = S[S.len]
//Then use that to calculate the "base dimension"-it will always be in multiples of 32 due to padding
//This will still work if there is only one icon_state for a single state icon
var/pos = findtext(TR,",")
var/x_off = text2num(copytext(TR,1,pos))
var/y_off = text2num(copytext(TR,pos+1))
var/xdimen = (x_off+1)*32
var/ydimen = (y_off+1)*32

//If we have multiple states, use the top right one otherwise, null for the default state
var/state
if(x_off || y_off)
state = "[x_off],[y_off]"

var/done = 0
var/xsub = 0
var/ysub = 0
var/c = 0
//Since BYOND pads to the top and right, check the pixels in the top right tile
//If we find a non-transparent pixel, that will be the end size adjustment
//If none are found, it assumes that the originally calculated dimension is "correct"
for(var/y=32;y > 0;y--)
for(var/x=32;x > 0;x--)
var/T = I.GetPixel(x,y,state)
if(T)
xsub = 32-x
ysub = 32-y
done = 1
break
if(done)break

xdimen -= xsub
ydimen -= ysub
world << "Image dimension is [xdimen] x [ydimen] pixels"