Look at DetermineFileFormat for details.
function ImDetermineFileFormat(FileName: PAnsiChar; Ext: PAnsiChar): Boolean; cdecl;
ImagingExport (at line 55)
Ext should have enough space for result file extension.