fix: apply EXIF orientation to service record images in PDF/DOCX
Smartphone photos often have EXIF orientation metadata (tags 6, 8, 3) that rotates the display but doesn't transform the pixel data. When PDFs/DOCX embedded images without applying this metadata, they appear rotated 90/180/270 degrees. Use ImageOps.exif_transpose(img) before resize/convert in both _compress_image_for_pdf() and _compress_image_for_docx() to read EXIF orientation and transpose the actual pixel data accordingly. This is a standard Pillow function and is a no-op for images without EXIF. Add regression test test_compress_image_for_docx_handles_exif_orientation to verify images with EXIF tag 0x0112 (orientation=6) are transposed. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -252,6 +252,20 @@ class WorkOrderImagesEndpointTests(TestCase):
|
||||
self.assertIsNotNone(result)
|
||||
self.assertGreater(len(result.getvalue()), 0)
|
||||
|
||||
def test_compress_image_for_docx_handles_exif_orientation(self):
|
||||
exif = Image.Exif()
|
||||
exif[0x0112] = 6
|
||||
|
||||
file = BytesIO()
|
||||
Image.new('RGB', (3000, 2000), color='green').save(file, format='JPEG', quality=85, exif=exif.tobytes())
|
||||
file.seek(0)
|
||||
uploaded = SimpleUploadedFile('rotated-phone.jpg', file.getvalue(), content_type='image/jpeg')
|
||||
|
||||
result = _compress_image_for_docx(uploaded)
|
||||
|
||||
self.assertIsNotNone(result)
|
||||
self.assertGreater(len(result.getvalue()), 0)
|
||||
|
||||
def test_work_order_related_tasks_queryset_excludes_other_work_orders_for_same_vehicle(self):
|
||||
other_work_order = WorkOrder.objects.create(
|
||||
vehicle=self.vehicle,
|
||||
|
||||
Reference in New Issue
Block a user