Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions backend/database/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class ImageModel(DynamicDocument):
THUMBNAIL_DIRECTORY = '.thumbnail'
PATTERN = (".gif", ".png", ".jpg", ".jpeg", ".bmp", ".GIF", ".PNG", ".JPG", ".JPEG", ".BMP")

# Set maximum thumbnail size (h x w) to use on dataset page
MAX_THUMBNAIL_DIM = (1024, 1024)

# -- Private
_dataset = None

Expand Down Expand Up @@ -89,9 +92,6 @@ def thumbnail(self):
"""
Generates (if required) and returns thumbnail
"""
if not self.annotated:
self.thumbnail_delete()
return Image.open(self.path)

thumbnail_path = self.thumbnail_path()

Expand All @@ -102,7 +102,13 @@ def thumbnail(self):

pil_image = self.generate_thumbnail()
pil_image = pil_image.convert("RGB")
pil_image.save(thumbnail_path)

# Resize image to fit in MAX_THUMBNAIL_DIM envelope as necessary
pil_image.thumbnail((self.MAX_THUMBNAIL_DIM[1], self.MAX_THUMBNAIL_DIM[0]))

# Save as a jpeg to improve loading time
# (note file extension will not match but allows for backwards compatibility)
pil_image.save(thumbnail_path, "JPEG", quality=80, optimize=True, progressive=True)

self.update(is_modified=False)
return pil_image
Expand Down
2 changes: 1 addition & 1 deletion backend/webserver/api/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def post(self):
set__metadata=image.get('metadata', {}),
set__annotated=annotated,
set__category_ids=image.get('category_ids', []),
set__regenerate_thumbnail=annotated,
set__regenerate_thumbnail=True,
set__num_annotations=annotations\
.filter(deleted=False, area__gt=0).count()
)
Expand Down
2 changes: 1 addition & 1 deletion client/src/components/cards/ImageCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ export default {
computed: {
imageUrl() {
let d = new Date();
if (this.image.annotated && this.showAnnotations) {
if (this.showAnnotations) {
return `/api/image/${
this.image.id
}?width=250&thumbnail=true&dummy=${d.getTime()}`;
Expand Down