-
Notifications
You must be signed in to change notification settings - Fork 324
Adding Image Resizer Project #1804
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
Open
SowmyaKurapati26
wants to merge
4
commits into
UTSAVS26:main
Choose a base branch
from
SowmyaKurapati26:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+177
−117
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import os | ||
| import tkinter as tk | ||
| from tkinter import filedialog, messagebox, ttk | ||
| from PIL import Image | ||
|
|
||
|
|
||
| class ImageResizerApp: | ||
| def __init__(self, root): | ||
| self.root = root | ||
| self.root.title("Image Resizer") | ||
| self.root.geometry("500x350") | ||
| self.root.configure(bg="#2b2b2b") | ||
|
|
||
| self.images = [] | ||
| self.output_folder = os.path.join(os.getcwd(), "output") | ||
|
|
||
| self._build_ui() | ||
|
|
||
| def _build_ui(self): | ||
| style = ttk.Style() | ||
| style.theme_use("clam") | ||
| style.configure("TButton", background="#444444", foreground="white") | ||
| style.configure("TLabel", background="#2b2b2b", foreground="white") | ||
|
|
||
| # Select Images | ||
| ttk.Button(self.root, text="📂 Select Images", command=self._select_images).pack(pady=10) | ||
|
|
||
| # Width/Height | ||
| frame1 = tk.Frame(self.root, bg="#2b2b2b") | ||
| frame1.pack(pady=5) | ||
| tk.Label(frame1, text="Width:", bg="#2b2b2b", fg="white").grid(row=0, column=0, padx=5) | ||
| self.width_entry = tk.Entry(frame1, bg="#3c3f41", fg="white") | ||
| self.width_entry.grid(row=0, column=1, padx=5) | ||
|
|
||
| tk.Label(frame1, text="Height:", bg="#2b2b2b", fg="white").grid(row=0, column=2, padx=5) | ||
| self.height_entry = tk.Entry(frame1, bg="#3c3f41", fg="white") | ||
| self.height_entry.grid(row=0, column=3, padx=5) | ||
|
|
||
| # Percentage | ||
| frame2 = tk.Frame(self.root, bg="#2b2b2b") | ||
| frame2.pack(pady=5) | ||
| tk.Label(frame2, text="Scale (%):", bg="#2b2b2b", fg="white").grid(row=0, column=0, padx=5) | ||
| self.scale_entry = tk.Entry(frame2, bg="#3c3f41", fg="white") | ||
| self.scale_entry.grid(row=0, column=1, padx=5) | ||
|
|
||
| # Output folder | ||
| ttk.Button(self.root, text="📁 Select Output Folder", command=self._select_output_folder).pack(pady=10) | ||
|
|
||
| # Resize button | ||
| ttk.Button(self.root, text="⚡ Resize", command=self._resize_images).pack(pady=10) | ||
|
|
||
| def _select_images(self): | ||
| files = filedialog.askopenfilenames( | ||
| title="Select Images", | ||
| filetypes=[("Image Files", "*.jpg *.jpeg *.png *.bmp *.gif")] | ||
| ) | ||
| if files: | ||
| self.images = files | ||
| messagebox.showinfo("Selected", f"{len(files)} image(s) selected.") | ||
|
|
||
| def _select_output_folder(self): | ||
| folder = filedialog.askdirectory(title="Select Output Folder") | ||
| if folder: | ||
| self.output_folder = folder | ||
| messagebox.showinfo("Output Folder", f"Output folder set to:\n{folder}") | ||
|
|
||
| def _resize_images(self): | ||
| if not self.images: | ||
| messagebox.showerror("Error", "No images selected.") | ||
| return | ||
|
|
||
| width = self.width_entry.get() | ||
| height = self.height_entry.get() | ||
| scale = self.scale_entry.get() | ||
|
|
||
| try: | ||
| width = int(width) if width else None | ||
| height = int(height) if height else None | ||
| scale = int(scale) if scale else None | ||
|
|
||
| for img_path in self.images: | ||
| self._resize_single(img_path, width, height, scale) | ||
|
|
||
| messagebox.showinfo("Success", "Images resized successfully!") | ||
|
|
||
| except Exception as e: | ||
| messagebox.showerror("Error", str(e)) | ||
|
|
||
| def _resize_single(self, input_path, width, height, scale): | ||
| img = Image.open(input_path) | ||
| orig_width, orig_height = img.size | ||
|
|
||
| if scale: | ||
| width = int(orig_width * scale / 100) | ||
| height = int(orig_height * scale / 100) | ||
| elif width and height: | ||
| width, height = int(width), int(height) | ||
| else: | ||
| raise ValueError("Provide width/height or scale.") | ||
|
|
||
| resized = img.resize((width, height), Image.Resampling.LANCZOS) | ||
|
|
||
| os.makedirs(self.output_folder, exist_ok=True) | ||
| base, ext = os.path.splitext(os.path.basename(input_path)) | ||
| output_file = os.path.join(self.output_folder, f"{base}_resized{ext}") | ||
| resized.save(output_file) | ||
|
|
||
| def run(self): | ||
| self.root.mainloop() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| root = tk.Tk() | ||
| app = ImageResizerApp(root) | ||
| app.run() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| # 🖼️ Image Resizer (GUI) | ||
|
|
||
| A **lightweight Python desktop app** to resize images (JPG/PNG/BMP/GIF) with ease. | ||
| Built using **Tkinter** for GUI and **Pillow** for image processing. | ||
|
|
||
| --- | ||
|
|
||
| ## ✨ Features | ||
|
|
||
| - 📂 Select one or more images. | ||
| - 📏 Resize by **custom width & height** (in pixels). | ||
| - ➗ Resize by **percentage scale** (e.g., 50%). | ||
| - 💾 Save resized images in an **output folder** with `_resized` suffix. | ||
| - ⚡ Lightweight, dependency-minimal, and beginner-friendly. | ||
| - 🌑 Modern dark-themed interface. | ||
|
|
||
| --- | ||
|
|
||
| ## 📂 Project Structure | ||
|
|
||
| ``` | ||
| image_resizer/ | ||
| │── app.py # Full application (GUI + logic) | ||
| └── output/ # Resized images are saved here | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## 🛠️ Requirements | ||
|
|
||
| - Python 3.8+ | ||
| - [Pillow](https://pypi.org/project/pillow/) (PIL fork, for image processing) | ||
|
|
||
| Install dependency: | ||
|
|
||
| ```bash | ||
| pip install pillow | ||
| ``` | ||
|
Comment on lines
+31
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick Pin minimal Pillow version required by code.
-```bash
-pip install pillow
-```
+```bash
+pip install "pillow>=9.1.0"
+```🤖 Prompt for AI Agents |
||
|
|
||
| --- | ||
|
|
||
| ## 📖 Usage | ||
|
|
||
| 1. Click **“📂 Select Images”** → choose one or more images. | ||
| 2. Enter either: | ||
|
|
||
| - **Width + Height** (pixels), or | ||
| - **Scale (%)** (e.g., 50 = half size). | ||
|
|
||
| 3. (Optional) Choose a custom output folder. | ||
| 4. Click **“⚡ Resize”** → resized images will be saved with `_resized` suffix. | ||
|
|
||
| --- | ||
|
|
||
| ## 🖼️ Supported Formats | ||
|
|
||
| - JPG | ||
| - PNG | ||
| - BMP | ||
| - GIF | ||
|
|
||
| --- | ||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import needed PIL utilities and add LANCZOS fallback for older Pillow.
Prevents runtime errors on Pillow < 9.1.0 and enables safer handling.
📝 Committable suggestion
🤖 Prompt for AI Agents