Skip to content
Snippets Groups Projects

feat: add image render endpoint

Merged Konrad Mohrfeldt requested to merge kmohrf/image-render-endpoint into main
3 files
+ 55
2
Compare changes
  • Side-by-side
  • Inline
Files
3
+ 12
0
@@ -145,6 +145,18 @@ class Image(models.Model):
ppoi = PPOIField()
width = models.PositiveIntegerField(blank=True, null=True)
def render(self, width: int | None = None, height: int | None = None):
if width is None and height is None:
return self.image.url
elif width and height:
return self.image.crop[f"{width}x{height}"].url
aspect_ratio = self.width / self.height
if width is None:
width = int(height * aspect_ratio)
if height is None:
height = int(width / aspect_ratio)
return self.image.thumbnail[f"{width}x{height}"].url
def save(self, *args, **kwargs):
super().save(*args, **kwargs)
Loading