diff --git a/pandora/item/models.py b/pandora/item/models.py index 7ee4efa87..8249cd6e9 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1455,7 +1455,7 @@ class Item(models.Model): self.clear_poster_cache(self.poster.path) self.poster.delete() - if not self.poster: + if not self.poster or not os.path.exists(self.poster.path): poster = self.make_siteposter() url = self.prefered_poster_url() if url: diff --git a/pandora/item/views.py b/pandora/item/views.py index 966744eb8..3600086ea 100644 --- a/pandora/item/views.py +++ b/pandora/item/views.py @@ -827,6 +827,20 @@ def poster_frame(request, id, position): raise Http404 +def image_path_to_response(image, size=None): + if size: + size = int(size) + path = image.replace('.jpg', '.%d.jpg' % size) + if not os.path.exists(path): + image_size = max(Image.open(image).size) + if size > image_size: + path = image + else: + extract.resize_image(image, path, size=size) + else: + path = image + return HttpFileResponse(path, content_type='image/jpeg') + def image_to_response(image, size=None): if size: size = int(size) @@ -883,8 +897,12 @@ def poster(request, id, size=None): icon=item.icon.name, cache=item.json() ) + siteposter = item.path('siteposter.jpg') + siteposter = os.path.abspath(os.path.join(settings.MEDIA_ROOT, siteposter)) if item.poster and os.path.exists(item.poster.path): return image_to_response(item.poster, size) + elif os.path.exists(siteposter): + return image_path_to_response(siteposter, size) else: return temp_poster()