Project: Color Picker

Color Picker Utility

This project is a Python script designed to pick a color from any given input image. It utilizes various libraries to process the image and output the selected color values.

Technical Documentation

The Color Picker utility processes images to extract color information, providing RGB and HEX codes for the selected pixel. This documentation covers the workflow, libraries used, and the core logic of the script.

Code Snippet


import tkinter as tk
from tkinter import filedialog
from PIL import Image, ImageTk

class ColorPicker:
    def __init__(self, master):
        self.master = master
        self.canvas = tk.Canvas(master, width=400, height=400)
        self.canvas.pack()

        self.image_path = filedialog.askopenfilename()
        self.image = Image.open(self.image_path)
        self.photo = ImageTk.PhotoImage(self.image)
        self.canvas.create_image(20, 20, anchor=tk.NW, image=self.photo)
        self.canvas.bind('', self.pick_color)

    def pick_color(self, event):
        x, y = event.x, event.y
        image = self.image.convert("RGB")
        r, g, b = image.getpixel((x, y))
        color = f'#{r:02x}{g:02x}{b:02x}'
        print(f'RGB: ({r}, {g}, {b}), HEX: {color}')

root = tk.Tk()
cp = ColorPicker(root)
root.mainloop()
            

Replace this code snippet with the actual code from your project, and describe its functionality and components.