if res:
return bytes(res.data)
- async def get_thumbnail(self, size):
+ async def get_thumbnail(self, size, format=None):
assert self.is_bitmap_image()
- cache_key = "-".join((
+ cache_key = ":".join((
+ "wiki",
+ "thumbnail",
self.path,
util.normalize(self.filename),
self.created_at.isoformat(),
+ format or "N/A",
"%spx" % size,
))
return thumbnail
# Generate the thumbnail
- thumbnail = util.generate_thumbnail(self.blob, size)
+ thumbnail = util.generate_thumbnail(self.blob, size, format=format)
# Put it into the cache for forever
await self.backend.cache.set(cache_key, thumbnail)
self.render("docs/files/detail.html", page=page, file=file)
return
+ # Get image size
size = self.get_argument_int("s", None)
# Check if image should be resized
if size and file.is_bitmap_image():
- blob = await file.get_thumbnail(size)
+ # Send WEBP if the browser supports
+ if self.browser_accepts("image/webp"):
+ format = "WEBP"
+
+ # Fall back to the native format
+ else:
+ format = None
+
+ blob = await file.get_thumbnail(size, format=format)
else:
blob = file.blob