'To fix the exif orientation to 1 and correct the rest of the attributes

I know about rotating the image by checking the orientation tag of the exif.
However, I would like to modify the rest of the tags in the exif as well.
The converted result should be implemented as if an exif was written by a camera that satisfies orientation=1.

>> exif IMG_8785.jpg 
EXIF tags in 'IMG_8785.jpg' ('Motorola' byte order):
--------------------+----------------------------------------------------------
Tag                 |Value
--------------------+----------------------------------------------------------
Manufacturer        |Apple
Model               |iPhone 12 Pro
Orientation         |Right-top
X-Resolution        |72
Y-Resolution        |72
Resolution Unit     |Inch
Software            |15.4.1
...
Subject Area        |Within rectangle (width 2318, height 1390) around (x,y) = 
...
Pixel X Dimension   |4032
Pixel Y Dimension   |3024

This is an example I took with my camera.
The orientation of this camera is 8.

I know how to transform an image to what it will look like when orientation=1.
Is there an implementation that properly modifies the rest of EXIF tags by changing orientation=1 as well?

For example, what needs to be modified in the example above would be as follows.

Subject Area        |Within rectangle (width 1390, height 2318) around (x,y) = 
...
Pixel X Dimension   |3024
Pixel Y Dimension   |4032

After seeing a lot of tags and rules on EXIF, I thought someone might have implemented it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source