Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 115 additions & 0 deletions Advanced_Projects/Image_resizer/app.py
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:
Comment on lines +4 to +7
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Import needed PIL utilities and add LANCZOS fallback for older Pillow.

Prevents runtime errors on Pillow < 9.1.0 and enables safer handling.

-from PIL import Image
+from PIL import Image, UnidentifiedImageError, ImageOps
+
+# Pillow < 9.1.0 fallback
+try:
+    RESAMPLE = Image.Resampling.LANCZOS
+except AttributeError:  # pragma: no cover
+    RESAMPLE = Image.LANCZOS
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from PIL import Image
class ImageResizerApp:
from PIL import Image, UnidentifiedImageError, ImageOps
# Pillow < 9.1.0 fallback
try:
RESAMPLE = Image.Resampling.LANCZOS
except AttributeError: # pragma: no cover
RESAMPLE = Image.LANCZOS
class ImageResizerApp:
🤖 Prompt for AI Agents
In Advanced_Projects/Image_resizer/app.py around lines 4 to 7, add the missing
PIL utility imports and a compatibility fallback for the LANCZOS resampling
constant: import the required PIL modules (e.g., Image and any utilities you
use) and define a module-level LANCZOS constant using a try/except that prefers
Image.Resampling.LANCZOS and falls back to Image.LANCZOS for older Pillow
versions so resampling calls work across Pillow <9.1.0 and newer releases.

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()
62 changes: 62 additions & 0 deletions Advanced_Projects/Image_resizer/readme.md
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick

Pin minimal Pillow version required by code.

Image.Resampling needs Pillow ≥ 9.1.0.

-```bash
-pip install pillow
-```
+```bash
+pip install "pillow>=9.1.0"
+```
🤖 Prompt for AI Agents
In Advanced_Projects/Image_resizer/readme.md around lines 31 to 38, the
dependency note currently installs Pillow without a version pin even though the
code uses Image.Resampling which requires Pillow >= 9.1.0; update the
installation instruction to pin the minimal required version by replacing the
pip install line with pip install "pillow>=9.1.0" so the correct Pillow API is
available.


---

## 📖 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

---
117 changes: 0 additions & 117 deletions Cybersecurity_Tools/Reverse_backdoor/backdoor.py

This file was deleted.