How to rotate each image of the post separately?

Oh no, I think I misread your question to be about WHY it does not rotate from a script you use in your asset pipeline. In general, if images rotate without YOU doing anything then they have an EXIF tag that tells us to rotate. If you hold your camera at an angle it sets this tag by itself and modern browsers and most file explorers read these tags and rotate accordingly.

I never had the need to rotate images, but maybe this post and it’s answers will help you: Image EXIF orientation