0

I am trying to crop an image using PIL.image.crop() and then determine the most dominant color in the cropped image. I've tried using ColorThief but it will only analyze an image if a path to the image is specified, and I don't want to have to save a file to my device every time I run the program. Is there a way to find the dominant color without saving the cropped image to my device?

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 14 11:39:07 2022

@author: nickr
"""
from PIL import Image
from colorthief import ColorThief

im = Image.open("C:/Users/nickr/Desktop/right.png")

im1 = im.crop((0, 0, 50, 50)) #gives top left grid cell
im1.show()


color_thief = ColorThief(im1) #this will not work because it is not a path

im1Color = color_thief.get_color(quality=1)
print(im1Color)
nickreitz
  • 43
  • 4
  • Write your cropped image data to an `io.BytesIO` object, then pass that to colorthief. See my answer [here](https://stackoverflow.com/a/68985992/1426065) for an example. – MattDMo Sep 20 '22 at 00:53
  • always put FULL error message (starting at word "Traceback") in question (not in comments) as text (not screenshot, not link to external portal). There are other useful information in the full error/traceback. – furas Sep 20 '22 at 03:38

0 Answers0