├── .github └── workflows │ └── pylint.yml ├── main.py └── README.md /.github/workflows/pylint.yml: -------------------------------------------------------------------------------- 1 | name: Pylint 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | python-version: ["3.8", "3.9", "3.10"] 11 | steps: 12 | - uses: actions/checkout@v4 13 | - name: Set up Python ${{ matrix.python-version }} 14 | uses: actions/setup-python@v3 15 | with: 16 | python-version: ${{ matrix.python-version }} 17 | - name: Install dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | pip install pylint 21 | - name: Analysing the code with pylint 22 | run: | 23 | pylint $(git ls-files '*.py') 24 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import io 3 | import tkinter as tk 4 | from tkinter import ttk, filedialog 5 | from PIL import Image, ImageTk 6 | from ttkbootstrap import Style 7 | 8 | root = tk.Tk() 9 | root.title("Image Generator") 10 | root.geometry("700x600") 11 | root.config(bg="grey") 12 | root.resizable(False, False) 13 | style = Style(theme="sandstone") 14 | 15 | style.configure('TButton', font=('Helvetica', 12), padding=10) 16 | style.configure('like.TButton', foreground='green', background='white') 17 | style.configure('unlike.TButton', foreground='red', background='white') 18 | style.configure('download.TButton', foreground='blue', background='white') 19 | 20 | current_image_data = None 21 | current_image_url = None 22 | 23 | def display_image(category): 24 | global current_image_data, current_image_url 25 | 26 | url = f"https://api.unsplash.com/photos/random?query={category}&orientation=landscape&client_id=Gb78V27Jp6lime1lAKzYaJW_sUOn8Zh5ujWc0lbjF7o&w=3840&h=2160" 27 | try: 28 | response = requests.get(url) 29 | response.raise_for_status() 30 | data = response.json() 31 | current_image_url = data["urls"]["raw"] 32 | 33 | img_data = requests.get(current_image_url).content 34 | 35 | photo = ImageTk.PhotoImage(Image.open(io.BytesIO(img_data)).resize((600, 400), resample=Image.LANCZOS)) 36 | label.config(image=photo) 37 | label.image = photo 38 | like_button.config(state="normal") 39 | unlike_button.config(state="normal") 40 | download_button.config(state="normal") 41 | 42 | current_image_data = img_data 43 | except requests.exceptions.RequestException as e: 44 | print(f"Error requesting data from Unsplash API: {e}") 45 | 46 | def enable_button(*args): 47 | generate_button.config(state="normal" if category_var.get() != "Choose Category" else "disabled") 48 | 49 | def like_image(): 50 | print("Image liked!") 51 | 52 | def unlike_image(): 53 | print("Image unliked!") 54 | 55 | def download_image(): 56 | global current_image_url, current_image_data 57 | 58 | if current_image_url and current_image_data: 59 | file_path = filedialog.asksaveasfilename(defaultextension=".jpg", filetypes=[("JPEG files", "*.jpg"), ("All files", "*.*")]) 60 | if file_path: 61 | try: 62 | with open(file_path, 'wb') as file: 63 | file.write(current_image_data) 64 | print(f"Image saved to {file_path}") 65 | except IOError as e: 66 | print(f"Error saving image: {e}") 67 | 68 | def start_generation(): 69 | display_image(category_var.get()) 70 | 71 | def exit_program(): 72 | root.destroy() 73 | 74 | def create_gui(): 75 | global category_var, generate_button, label, like_button, unlike_button, download_button 76 | 77 | category_var = tk.StringVar(value="Choose Category") 78 | category_options = ["Choose Category", "Food", "Animals", "People", "Marvel", "Art", "Technology", "Vehicles", "Moon", "Sky", "love", "Aesthetic", "Babies", "Random"] 79 | category_dropdown = ttk.OptionMenu(root, category_var, *category_options, command=enable_button) 80 | category_dropdown.grid(row=0, column=0, padx=10, pady=10, sticky="nsew") 81 | category_dropdown.config(width=14) 82 | 83 | generate_button = ttk.Button(text="Generate Image", state="disabled", command=start_generation) 84 | generate_button.grid(row=0, column=1, padx=10, pady=10, sticky="nsew") 85 | 86 | label = tk.Label(root, background="white") 87 | label.grid(row=1, column=0, columnspan=2, padx=10, pady=10, sticky="nsew") 88 | 89 | like_button = ttk.Button(root, text="Like", state="disabled", command=like_image, style="like.TButton") 90 | like_button.grid(row=2, column=0, padx=10, pady=10, sticky="nsew") 91 | 92 | unlike_button = ttk.Button(root, text="Unlike", state="disabled", command=unlike_image, style="unlike.TButton") 93 | unlike_button.grid(row=2, column=1, padx=10, pady=10, sticky="nsew") 94 | 95 | download_button = ttk.Button(root, text="Download", state="disabled", command=download_image, style="download.TButton") 96 | download_button.grid(row=3, column=0, columnspan=2, padx=10, pady=10, sticky="nsew") 97 | 98 | start_button = ttk.Button(root, text="Start", command=start_generation) 99 | start_button.grid(row=4, column=0, padx=10, pady=10, sticky="nsew") 100 | 101 | exit_button = ttk.Button(root, text="Exit", command=exit_program) 102 | exit_button.grid(row=4, column=1, padx=10, pady=10, sticky="nsew") 103 | 104 | root.columnconfigure([0, 1], weight=1) 105 | root.rowconfigure(1, weight=1) 106 | root.mainloop() 107 | 108 | if __name__ == '__main__': 109 | create_gui() 110 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

I am thrilled to announce the development of my first Python application, ImagiMingle: a sophisticated Random Image Generator App leveraging the Unsplash API. This innovative tool is designed to provide users with a dynamic experience by generating random images in real-time. Users can explore a wide array of images, select their favorites, and engage with them by liking or disliking their choices. The application also offers the functionality to download images in high definition, ensuring that users have access to high-quality visuals. I am eager to see how this tool can be further enhanced and invite contributions to improve its features and functionality.
7 | 8 | 9 |
12 |
13 | This application, ImagiMingle, is a Python-based Random Image Generator that utilizes the Unsplash API to fetch and display images. While the application is designed to provide a user-friendly experience, it is important to note the following: 15 | 16 |
44 |
45 |
46 | 1. Clone the repository
49 | 50 | ```bash 51 | git clone https://github.com/Minhal128/ImagiMingle.git 52 | ``` 53 | 54 |2. Install & Run python Language & its modules
55 | 56 | ```bash Modules to Install 57 | pip install pillow 58 | pip install tkinter 59 | pip install ttkbootstrap 60 | 61 | ```bash 62 | # Run the executable 63 | python3 imagi_mingle.py 64 | or 65 | python imagi_mingle.py 66 | 67 | ``` 68 | 69 |71 |
120 |
121 | 135 | 136 |
159 |
160 |