diff --git a/geonode/base/api/tests.py b/geonode/base/api/tests.py index 5e7c8e611de..66c1d8a7347 100644 --- a/geonode/base/api/tests.py +++ b/geonode/base/api/tests.py @@ -2014,7 +2014,7 @@ def test_set_resource_thumbnail(self): _mck.return_value = False response = self.client.put(url, data=data, format="json") self.assertEqual(response.status_code, 200) - self.assertIsNotNone(re.search(f"dataset-{re_uuid}-thumb-{re_uuid}.png", Dataset.objects.get(pk=resource.pk).thumbnail_url, re.I)) + self.assertIsNotNone(re.search(f"dataset-{re_uuid}-thumb-{re_uuid}.jpg", Dataset.objects.get(pk=resource.pk).thumbnail_url, re.I)) # File upload with patch('PIL.Image.open') as _mck: _mck.return_value = test_image @@ -2024,7 +2024,7 @@ def test_set_resource_thumbnail(self): self.assertEqual(Dataset.objects.get(pk=resource.pk).thumbnail_url, None) f = SimpleUploadedFile('test_image.png', BytesIO(test_image.tobytes()).read(), 'image/png') response = self.client.put(url, data={"file": f}) - self.assertIsNotNone(re.search(f"dataset-{re_uuid}-thumb-{re_uuid}.png", Dataset.objects.get(pk=resource.pk).thumbnail_url, re.I)) + self.assertIsNotNone(re.search(f"dataset-{re_uuid}-thumb-{re_uuid}.jpg", Dataset.objects.get(pk=resource.pk).thumbnail_url, re.I)) self.assertEqual(response.status_code, 200) def test_set_thumbnail_from_bbox_from_Anonymous_user_raise_permission_error(self): diff --git a/geonode/base/models.py b/geonode/base/models.py index fd619e89b07..f991d0fcb67 100644 --- a/geonode/base/models.py +++ b/geonode/base/models.py @@ -1723,6 +1723,8 @@ def has_thumbnail(self): # that indexing (or other listeners) are notified def save_thumbnail(self, filename, image): upload_path = get_unique_upload_path(filename) + # force convertion to JPEG output file + upload_path = f'{os.path.splitext(upload_path)[0]}.jpg' try: # Check that the image is valid if is_monochromatic_image(None, image): @@ -1743,14 +1745,11 @@ def save_thumbnail(self, filename, image): # Optimize the Thumbnail size and resolution _default_thumb_size = settings.THUMBNAIL_SIZE im = Image.open(storage_manager.open(actual_name)) - im.thumbnail( - (_default_thumb_size['width'], _default_thumb_size['height']), - resample=Image.ANTIALIAS) - cover = ImageOps.fit(im, (_default_thumb_size['width'], _default_thumb_size['height'])) + cover = ImageOps.fit(im, (_default_thumb_size['width'], _default_thumb_size['height'])).convert("RGB") # Saving the thumb into a temporary directory on file system tmp_location = os.path.abspath(f"{settings.MEDIA_ROOT}/{upload_path}") - cover.save(tmp_location, format='PNG') + cover.save(tmp_location, quality="high") with open(tmp_location, 'rb+') as img: # Saving the img via storage manager diff --git a/geonode/documents/tasks.py b/geonode/documents/tasks.py index d9968e8bbb9..2f293d03547 100644 --- a/geonode/documents/tasks.py +++ b/geonode/documents/tasks.py @@ -79,7 +79,7 @@ def create_document_thumbnail(self, object_id): logger.warning(f"Thumbnail for document #{object_id} empty.") ResourceBase.objects.filter(id=document.id).update(thumbnail_url=None) else: - filename = f'document-{document.uuid}-thumb.png' + filename = f'document-{document.uuid}-thumb.jpg' document.save_thumbnail(filename, thumbnail_content) logger.debug(f"Thumbnail for document #{object_id} created.") diff --git a/geonode/documents/tests.py b/geonode/documents/tests.py index f5311351710..8640a01e40a 100644 --- a/geonode/documents/tests.py +++ b/geonode/documents/tests.py @@ -301,6 +301,8 @@ def test_image_documents_thumbnail(self): ) file = Image.open(thumb_file) self.assertEqual(file.size, (400, 200)) + # check thumbnail qualty and extention + self.assertEqual(file.format, 'JPEG') finally: Document.objects.filter(title='img File Doc').delete() diff --git a/geonode/thumbs/tests/test_integration.py b/geonode/thumbs/tests/test_integration.py index 24bb2f20523..a3d084e2b8f 100644 --- a/geonode/thumbs/tests/test_integration.py +++ b/geonode/thumbs/tests/test_integration.py @@ -238,7 +238,7 @@ def test_tile_background_generic_fetch(self): ) def test_tile_background_generic_fetch_zoom(self): - width = 240 + width = 500 height = 200 bbox_3857 = [-8250483.072013094, -8221819.186406153, 4961221.562116772, 4985108.133455889, "EPSG:3857"]