Is there a way to get image pixel format for glTexImage2D() automatically?

Hi,

I am currently experimenting with glTexImage2D() with different image types, some of them are of RGB565, and some of them are 24 bit RGB images, I was trying to write some code that can automatically pass correct parameters to the glTexImage2D()'s 7th and 8th parameter for different pixel format, but can’t seem to find a way to do so.

I am using ImageMagick in loading the image files, does ImageMagick able to tell the difference in pixel format or do I need something else?

Thanks!