## Knowing if userdata is really an image

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

### Knowing if userdata is really an image

How?

So I can predict and avoid app crashes?

Because doing type(myImage) only tell me that it is userdata.

I could run through all elements in userdata and check if all of them are {r, g, b, a}, but since i'm implementing support for CMYK and HSV colors, it would be too much time invested for just that.

Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

### Re: Knowing if userdata is really an image

Assuming we're talking about Image objects, does this work?

Code: Select all

if image:typeOf("Image") then
Ubermann
Party member
Posts: 146
Joined: Mon Nov 05, 2012 4:00 pm

### Re: Knowing if userdata is really an image

Santos wrote:Assuming we're talking about Image objects, does this work?

Code: Select all

if image:typeOf("Image") then
No.

It is in fact ImageData type of object.
And when doing type() it just returns "userdata".
But I need to know if it really contains data that is image data or not.
ejmr
Party member
Posts: 302
Joined: Fri Jun 01, 2012 7:45 am
Location: South Carolina, U.S.A.
Contact:

### Re: Knowing if userdata is really an image

Ubermann wrote:But I need to know if it really contains data that is image data or not.
If you want there to be zero doubt about the nature of the data I don't see any other option besides reading the entire file and verifying it, byte-by-byte if you have to. Popular image formats have header metadata you could look at, but if you base the test just on that you're trusting the rest of the data to be uncorrupted.
ejmr :: Programming and Game-Dev Blog, GitHub

### Who is online

Users browsing this forum: Google [Bot] and 32 guests