Look at DetermineMemoryFormat for details.
function ImDetermineMemoryFormat(Data: Pointer; Size: LongInt; Ext: PAnsiChar): Boolean; cdecl;
ImagingExport (at line 58)
Ext should have enough space for result file extension.