This thread has some info:
It’s not super trivial unfortunately.
Do you have full control over those input images? Because it would be easier to pre-apply the rotation: ImBatch: Rotate Using EXIF Orientation Tag | High Motion Software (random google result for the task)