Incorrect width/height after image rotation applied by the blurring API
In order to correctly detect objects on EXIF/JPEG rotated pictures, the blurring API is rotating the picture losslessly using exiftran to have real pixel ordered vertically and horizontaly.
This causes height/width to be swapped which impact the viewer when displaying annotations in pictures.
The API is current extraction these value before the blurring step and stores them in exif + metadata jsonb fields and the value returned by the API do not reflect the real width/height of the available picture when they have been rotated.
Fix proposal:
- extract exif orientation and image width/height after the blurring step, and update the exif+medata fields
- apply a retroactive SQL update to swap the width/height (in both exif+metadata fields) when exif orientation is 6 or 8 (90° and 270° rotations) and reset the orientation field
UPDATE pictures SET
exif=exif -'Exif.Image.Orientation' || jsonb_build_object('Exif.Photo.PixelXDimension', exif->'Exif.Photo.PixelYDimension','Exif.Photo.PixelYDimension',exif->'Exif.Photo.PixelXDimension'),
metadata=metadata || jsonb_build_object('width',metadata->'height','height',metadata->'width')
WHERE exif->>'Exif.Image.Orientation' in ('6','8');
This makes sure values returned by the API are coherent with the actual picture, and limit changes only at the API level, not the blurring or viewer.