Open Myzel394 opened 4 years ago
I want to find out the dominant color of the image and store it in a field. This should happen in the save method.
save
I'm using a little version of this method: https://stackoverflow.com/a/34964548/9878135
class Model(models.Model): image = models.ImageField( storage=OverwriteStorage(), upload_to=image_path + "_org/", default=settings.DEFAULT_IMAGE_PATH, blank=True, ) def save(self, *args, **kwargs): self.create_dominant_color() super().save(*args, **kwargs) def create_dominant_color(self): self.dominant_color = get_dominant_color(self.image)
This is my get_dominant_color:
get_dominant_color
def get_dominant_color(image_file): im = Image.new(image.mode, image.size) # just added one line
When I try to call image.mode I get this error: 'ImageCacheFile' object has no attribute 'mode'.
image.mode
'ImageCacheFile' object has no attribute 'mode'
Would be nice if you could add the mode to the ImageCacheFile class.
ImageCacheFile
I want to find out the dominant color of the image and store it in a field. This should happen in the
save
method.I'm using a little version of this method: https://stackoverflow.com/a/34964548/9878135
This is my
get_dominant_color
:When I try to call
image.mode
I get this error:'ImageCacheFile' object has no attribute 'mode'
.Would be nice if you could add the mode to the
ImageCacheFile
class.