Skip to content

Commit

Permalink
[Fixes #4881] Improve initial generate thumbnail quality
Browse files Browse the repository at this point in the history
 - Fix pep8 issues
  • Loading branch information
afabiani committed Sep 12, 2019
1 parent 1cf9f32 commit 2ab57c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions geonode/geoserver/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1909,6 +1909,19 @@ def _render_thumbnail(req_body, width=240, height=180):
try:
req, content = http_client.post(
url, data=data, headers=headers)
# Optimize the Thumbnail size and resolution
from PIL import Image
from io import BytesIO
content_data = BytesIO(content)
im = Image.open(content_data)
im_width, im_height = im.size
right = min(width, im_width)
bottom = min(height, im_height)
size = right, bottom
im.thumbnail(size, Image.ANTIALIAS)
imgByteArr = BytesIO()
im.save(imgByteArr, format='JPEG')
content = imgByteArr.getvalue()
except BaseException as e:
logger.warning('Error generating thumbnail')
logger.exception(e)
Expand Down
2 changes: 1 addition & 1 deletion geonode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def zoom(mapPx, worldPx, fraction):
latZoom = zoom(float(height), WORLD_DIM['height'], latFraction)
lngZoom = zoom(float(width), WORLD_DIM['width'], lngFraction)
ratio = float(max(width, height)) / float(min(width, height))
z_offset = 0 if ratio >= 1.5 else -1
z_offset = 0 if ratio >= 2 else -1
zoom = int(max(latZoom, lngZoom) + z_offset)
zoom = 0 if zoom > ZOOM_MAX else zoom
return max(zoom, 0)
Expand Down

0 comments on commit 2ab57c0

Please sign in to comment.