Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the mode from the image? #493

Open
Myzel394 opened this issue Oct 2, 2019 · 0 comments
Open

How to get the mode from the image? #493

Myzel394 opened this issue Oct 2, 2019 · 0 comments

Comments

@Myzel394
Copy link

Myzel394 commented Oct 2, 2019

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

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:

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'.

Would be nice if you could add the mode to the ImageCacheFile class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant