我想编写一个检测上传图像方向的方法,然后使用 django-imagekit 使用具有特定横向或纵向尺寸的拇指。有任何想法吗?
class Photo(models.Model):
title = models.CharField(max_length=200)
photo = models.ImageField(upload_to='/photos', max_length=50)
photoalbum = models.ForeignKey(Photoalbum, related_name='photos')
portrait_thumb = ImageSpecField(source='photo',
processors=[ResizeToFill(50, 100)],
format='JPEG',
options={'quality': 60})
landscape_thumb = ImageSpecField(source='photo',
processors=[ResizeToFill(100, 50)],
format='JPEG',
options={'quality': 60})
def get_orientation(self):
'''HOW TO IMPLEMENT THIS?'''
def get_thumb_url(self):
if self.get_orientation == 'portrait':
return self.portrait_thumb.url()
elif self.get_orientation == 'landscape':
return self.landscape_thumb.url()