├── README.md ├── firstPage.py └── im.py /README.md: -------------------------------------------------------------------------------- 1 | # Image Design Project 🎨📸 2 | 3 | Welcome to the Image Design Project repository! This project is focused on creating and designing beautiful and functional images for various applications. 4 | 5 | ## Features ✨ 6 | 7 | - **Image Editing** 🖼️: Enhance and modify images with ease. 8 | - **Filters** 🎛️: Apply a variety of filters to your images. 9 | - **Export Options** 📤: Export your images in multiple formats. 10 | - **User-Friendly Interface** 👥: Easy-to-use interface for seamless experience. 11 | 12 | ## Getting Started 🚀 13 | 14 | Follow these instructions to get a copy of the project up and running on your local machine. 15 | 16 | ### Prerequisites 📋 17 | 18 | Make sure you have the following software installed: 19 | - [Python](https://www.python.org/) 3.x 20 | - [Pip](https://pip.pypa.io/en/stable/) 21 | 22 | ### Installation 🔧 23 | 24 | 1. Clone the repository: 25 | ```bash 26 | git clone https://github.com/chedva-josefsberg/Image-design.git 27 | ``` 28 | 2. Navigate to the project directory: 29 | ```bash 30 | cd Image-design 31 | ``` 32 | 3. Install the required packages: 33 | ```bash 34 | pip install -r requirements.txt 35 | ``` 36 | 37 | ## Usage 🛠️ 38 | 39 | To start the application, run the following command: 40 | ```bash 41 | python main.py 42 | ``` 43 | -------------------------------------------------------------------------------- /firstPage.py: -------------------------------------------------------------------------------- 1 | from tkinter import * 2 | from tkinter import filedialog 3 | import im 4 | 5 | 6 | class MyWindow: 7 | def __init__(self): 8 | self.win = Tk() 9 | self.win.title("Edit Image") 10 | self.win.configure(bg='#FFA0CB') 11 | self.img = None 12 | 13 | self.btn1 = Button(self.win, text="Upload Image", width=15, height=3, background="pink", command=self.upload_image) 14 | self.btn2 = Button(self.win, text="Filters", width=15, height=3, background="pink" , command=self.filter) 15 | self.btn3 = Button(self.win, text="Cut", width=15, height=3, background="pink", command=self.cut) 16 | self.btn4 = Button(self.win, text="Add Text", width=15, height=3, background="pink", command=self.text) 17 | self.btn5 = Button(self.win, text="Add Shape", width=15, height=3, background="pink", command=self.draw) 18 | self.btn6 = Button(self.win, text="Rotate", width=15, height=3, background="pink", command= self.rotate) 19 | self.btn7 = Button(self.win, text="Save as", width=15, height=3, background="pink", command=self.save_image) 20 | self.btn8 = Button(self.win, text="Exit", width=15, height=3, background="pink", command=self.exit_application) 21 | 22 | self.positions() 23 | self.win.mainloop() 24 | 25 | def positions(self): 26 | self.btn1.grid(row=0, column=0, padx=20, pady=10) 27 | self.btn2.grid(row=0, column=1, padx=20, pady=10) 28 | self.btn3.grid(row=1, column=0, padx=20, pady=10) 29 | self.btn4.grid(row=1, column=1, padx=20, pady=10) 30 | self.btn5.grid(row=2, column=0, padx=20, pady=10) 31 | self.btn6.grid(row=2, column=1, padx=20, pady=10) 32 | self.btn7.grid(row=3, column=0, padx=20, pady=10) 33 | self.btn8.grid(row=3, column=1, padx=20, pady=10) 34 | 35 | def exit_application(self): 36 | self.win.destroy() # close window 37 | 38 | def upload_image(self): 39 | file_path = filedialog.askopenfilename() 40 | if file_path: 41 | print("נבחרה תמונה:", file_path) 42 | self.img = im.MyImage(file_path, "window1") 43 | 44 | def text(self): 45 | self.img.add_text() 46 | 47 | def rotate(self): 48 | self.img.rotate() 49 | 50 | def filter(self): 51 | self.img.filter() 52 | 53 | def draw(self): 54 | self.img.draw_rec() 55 | 56 | def cut(self): 57 | self.img.cut() 58 | 59 | def save_image(self): 60 | if self.img is not None: 61 | file_path = filedialog.asksaveasfilename(defaultextension=".png") 62 | if file_path: 63 | self.img.save_image(file_path) 64 | print("Image saved successfully.") 65 | else: 66 | print("Save operation canceled.") 67 | else: 68 | print("No image loaded.") 69 | 70 | def close_window(self): 71 | self.win.destroy() 72 | 73 | 74 | w = MyWindow() 75 | -------------------------------------------------------------------------------- /im.py: -------------------------------------------------------------------------------- 1 | from tkinter import filedialog 2 | from tkinter.simpledialog import askstring 3 | import cv2 4 | import imageio 5 | 6 | class MyImage: 7 | # כאן יכתבו כל הפונקציות שמטפלות בתמונה עצמה 8 | def __init__(self, path, nameWindow): 9 | self.nameWindow = nameWindow 10 | self.path = path 11 | self.image = imageio.imread(path) 12 | self.image = cv2.cvtColor(self.image, cv2.COLOR_RGB2BGR) 13 | self.image = cv2.resize(self.image, (800, 500)) 14 | self.orig_image = self.image.copy() 15 | self.start_point = None 16 | self.end_point = None 17 | self.cropping = False 18 | self.show() 19 | 20 | def show(self): 21 | cv2.imshow(self.nameWindow, self.image) 22 | 23 | def add_text(self): 24 | text = askstring("Enter Text", "Enter the text you want to add:") 25 | if text: 26 | def add_text_event(event, x, y, flags, param): 27 | if event == cv2.EVENT_LBUTTONDOWN: 28 | font = cv2.FONT_HERSHEY_SIMPLEX 29 | cv2.putText(self.image, text, (x, y), font, 1, (255, 255, 255), 2, cv2.LINE_AA) 30 | self.show() 31 | cv2.setMouseCallback(self.nameWindow, add_text_event) 32 | 33 | def filter(self): 34 | self.image = cv2.applyColorMap(self.image, cv2.COLORMAP_JET) 35 | self.show() 36 | 37 | def draw_rec(self): 38 | def draw_rect_event(event, x, y, flags, param): 39 | global ix, iy 40 | if event == cv2.EVENT_LBUTTONDOWN: 41 | # לחצנו על העכבר השמאלי 42 | # אנחנו רוצים להתחיל לצייר ריבוע 43 | ix = x 44 | iy = y 45 | 46 | elif event == cv2.EVENT_LBUTTONUP: 47 | # סיימנו לצייר 48 | cv2.rectangle(self.image, (ix, iy), (x, y), (100, 50, 200), 8) 49 | self.show() 50 | 51 | cv2.setMouseCallback(self.nameWindow, draw_rect_event) 52 | 53 | def cut(self): 54 | def cut_image(event, x, y, flags, param): 55 | if event == cv2.EVENT_LBUTTONDOWN: 56 | self.start_point = (x, y) 57 | self.cropping = True 58 | 59 | elif event == cv2.EVENT_MOUSEMOVE: 60 | if self.cropping: 61 | self.image = self.orig_image.copy() 62 | cv2.rectangle(self.image, self.start_point, (x, y), (0, 0, 255), 2) 63 | self.show() 64 | 65 | elif event == cv2.EVENT_LBUTTONUP: 66 | self.end_point = (x, y) 67 | self.cropping = False 68 | cv2.rectangle(self.image, self.start_point, self.end_point, (0, 0, 255), 2) 69 | self.show() 70 | self.crop_and_save() 71 | 72 | cv2.setMouseCallback(self.nameWindow, cut_image) 73 | 74 | def crop_and_save(self): 75 | if self.start_point and self.end_point: 76 | x1, y1 = self.start_point 77 | x2, y2 = self.end_point 78 | cropped_image = self.orig_image[y1:y2, x1:x2] 79 | cv2.imshow('Cropped Image', cropped_image) 80 | cv2.imwrite('cropped_image.jpg', cropped_image) 81 | 82 | def rotate(self): 83 | angle = float(askstring("Enter Angle", "Enter the rotation angle:")) 84 | if angle: 85 | height, width = self.image.shape[:2] 86 | center = (width / 2, height / 2) 87 | rotation_matrix = cv2.getRotationMatrix2D(center, angle, 1.0) 88 | self.image = cv2.warpAffine(self.image, rotation_matrix, (width, height)) 89 | self.show() 90 | 91 | def save_image(self, file_path): 92 | # תמיר את התמונה מתבנית BGR לתבנית RGB 93 | image_rgb = cv2.cvtColor(self.image, cv2.COLOR_BGR2RGB) 94 | # שמור את התמונה לקובץ באמצעות הספרייה imageio 95 | imageio.imwrite(file_path, image_rgb) 96 | print("Image saved successfully.") 97 | def run(self): 98 | while True: 99 | cv2.imshow(self.nameWindow, self.image) 100 | key = cv2.waitKey(1) & 0xFF 101 | if key == 27: # Escape key 102 | break 103 | 104 | 105 | cv2.destroyAllWindows() 106 | --------------------------------------------------------------------------------