├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── Compresssio.py
├── LICENSE
├── README.md
├── files
├── compresssio.ico
└── compresssio.png
├── requirements.txt
└── settings.py
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__
2 | Test.py
3 |
4 | *.bat
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 | # Contributor Covenant Code of Conduct
2 |
3 | ## Our Pledge
4 |
5 | In the interest of fostering an open and welcoming environment, we as
6 | contributors and maintainers pledge to making participation in our project and
7 | our community a harassment-free experience for everyone, regardless of age, body
8 | size, disability, ethnicity, sex characteristics, gender identity and expression,
9 | level of experience, education, socio-economic status, nationality, personal
10 | appearance, race, religion, or sexual identity and orientation.
11 |
12 | ## Our Standards
13 |
14 | Examples of behavior that contributes to creating a positive environment
15 | include:
16 |
17 | * Using welcoming and inclusive language
18 | * Being respectful of differing viewpoints and experiences
19 | * Gracefully accepting constructive criticism
20 | * Focusing on what is best for the community
21 | * Showing empathy towards other community members
22 |
23 | Examples of unacceptable behavior by participants include:
24 |
25 | * The use of sexualized language or imagery and unwelcome sexual attention or
26 | advances
27 | * Trolling, insulting/derogatory comments, and personal or political attacks
28 | * Public or private harassment
29 | * Publishing others' private information, such as a physical or electronic
30 | address, without explicit permission
31 | * Other conduct which could reasonably be considered inappropriate in a
32 | professional setting
33 |
34 | ## Our Responsibilities
35 |
36 | Project maintainers are responsible for clarifying the standards of acceptable
37 | behavior and are expected to take appropriate and fair corrective action in
38 | response to any instances of unacceptable behavior.
39 |
40 | Project maintainers have the right and responsibility to remove, edit, or
41 | reject comments, commits, code, wiki edits, issues, and other contributions
42 | that are not aligned to this Code of Conduct, or to ban temporarily or
43 | permanently any contributor for other behaviors that they deem inappropriate,
44 | threatening, offensive, or harmful.
45 |
46 | ## Scope
47 |
48 | This Code of Conduct applies both within project spaces and in public spaces
49 | when an individual is representing the project or its community. Examples of
50 | representing a project or community include using an official project e-mail
51 | address, posting via an official social media account, or acting as an appointed
52 | representative at an online or offline event. Representation of a project may be
53 | further defined and clarified by project maintainers.
54 |
55 | ## Enforcement
56 |
57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
58 | reported by contacting the project team at panchaldhruvn@gmail.com. All
59 | complaints will be reviewed and investigated and will result in a response that
60 | is deemed necessary and appropriate to the circumstances. The project team is
61 | obligated to maintain confidentiality with regard to the reporter of an incident.
62 | Further details of specific enforcement policies may be posted separately.
63 |
64 | Project maintainers who do not follow or enforce the Code of Conduct in good
65 | faith may face temporary or permanent repercussions as determined by other
66 | members of the project's leadership.
67 |
68 | ## Attribution
69 |
70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72 |
73 | [homepage]: https://www.contributor-covenant.org
74 |
75 | For answers to common questions about this code of conduct, see
76 | https://www.contributor-covenant.org/faq
77 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing Guidelines
2 |
3 | This documentation contains a set of guidelines to help you during the contribution process.
4 | We are happy to welcome all the contributions from anyone willing to improve/add new scripts to this project. Thank you for helping out and remember, **no contribution is too small.**
5 |
6 | # Submitting Contributions👩💻👨💻
7 | Below you will find the process and workflow used to review and merge your changes.
8 | ## Step 0 : Find an issue
9 | - Take a look at the Existing Issues or create your **own** Issues!
10 | - Wait for the Issue to be assigned to you after which you can start working on it.
11 | - Note : Every change in this project should/must have an associated issue.
12 |
13 | ## Step 1 : Fork the Project
14 | - Fork this Repository. This will create a Local Copy of this Repository on your Github Profile. Keep a reference to the original project in `upstream` remote.
15 | ```
16 | $ git clone https://github.com//
17 | $ cd
18 | $ git remote add upstream https://github.com//
19 | ```
20 |
21 | - If you have already forked the project, update your copy before working.
22 | ```
23 | $ git remote update
24 | $ git checkout
25 | $ git rebase upstream/
26 | ```
27 | ## Step 2 : Branch
28 | Create a new branch. Use its name to identify the issue your addressing.
29 | ```
30 | # It will create a new branch with name Branch_Name and switch to that branch
31 | $ git checkout -b branch_name
32 | ```
33 | ## Step 3 : Work on the issue assigned
34 | - Work on the issue(s) assigned to you.
35 | - Add all the files/folders needed.
36 | - After you've made changes or made your contribution to the project add changes to the branch you've just created by:
37 | ```
38 | # To add all new files to branch Branch_Name
39 | $ git add .
40 | ```
41 | ## Step 4 : Commit
42 | - To commit give a descriptive message for the convenience of reveiwer by:
43 | ```
44 | # This message get associated with all files you have changed
45 | $ git commit -m 'message
46 | ```
47 | - **NOTE**: A PR should have only one commit. Multiple commits should be squashed.
48 | ## Step 5 : Work Remotely
49 | - Now you are ready to your work to the remote repository.
50 | - When your work is ready and complies with the project conventions, upload your changes to your fork:
51 |
52 | ```
53 | # To push your work to your remote repository
54 | $ git push -u origin Branch_Name
55 | ```
56 | - Here is how your branch will look.
57 |
58 | ## Step 6 : Pull Request
59 | - Go to your repository in browser and click on compare and pull requests. Then add a title and description to your pull request that explains your contribution.
60 | - Voila! Your Pull Request has been submitted and will be reviewed by the moderators and merged.🥳
61 |
62 | ## Need more help?🤔
63 | You can refer to the following articles on basics of Git and Github and also contact the Project Mentors, in case you are stuck:
64 | - [Forking a Repo](https://help.github.com/en/github/getting-started-with-github/fork-a-repo)
65 | - [Cloning a Repo](https://help.github.com/en/desktop/contributing-to-projects/creating-an-issue-or-pull-request)
66 | - [How to create a Pull Request](https://opensource.com/article/19/7/create-pull-request-github)
67 | - [Getting started with Git and GitHub](https://towardsdatascience.com/getting-started-with-git-and-github-6fcd0f2d4ac6)
68 | - [Learn GitHub from Scratch](https://lab.github.com/githubtraining/introduction-to-github)
69 |
--------------------------------------------------------------------------------
/Compresssio.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 |
4 | import os
5 | import time
6 | import os.path
7 | import sys
8 | import tkinter as tk
9 | from tkinter import filedialog
10 | from tkinter import messagebox
11 | from tkinter import *
12 | import shutil
13 | import tinify
14 | from settings import *
15 | import threading
16 |
17 |
18 | class MainWindow:
19 |
20 | THIS_FOLDER_G = ""
21 | if getattr(sys, "frozen", False):
22 | THIS_FOLDER_G = os.path.dirname(sys.executable)
23 | else:
24 | THIS_FOLDER_G = os.path.dirname(os.path.realpath(__file__))
25 |
26 | def __init__(self, root):
27 | self.root = root
28 |
29 | # Thread for Compressing the Images.
30 |
31 | self.compress = None
32 |
33 | # Thread for Stoping the Compressing thread process.
34 |
35 | self.stop = None
36 | self.stopFlag = False
37 |
38 | self._folder_url1 = tk.StringVar()
39 | self._folder_url2 = tk.StringVar()
40 | self._api_key = tk.StringVar()
41 | self._status = tk.StringVar()
42 | self.raw_images_dir = ""
43 | self.save_dir = ""
44 | self.abs_image_path = ""
45 | self.raw_images = []
46 | self._status.set("---")
47 | self.SUPPORTED_FORMATS = ("jpg", "jpeg", "png")
48 |
49 | root.title("Compresssio")
50 | root.configure(bg="#eeeeee")
51 |
52 | try:
53 | icon_img = tk.Image(
54 | "photo", file=self.THIS_FOLDER_G + "./files/compresssio.ico"
55 | )
56 | root.call("wm", "iconphoto", root._w, icon_img)
57 | except Exception:
58 | pass
59 |
60 | self.menu_bar = tk.Menu(root, bg="#eeeeee", relief=tk.FLAT)
61 | self.menu_bar.add_command(label="Help!", command=self.show_help_callback)
62 | self.menu_bar.add_command(label="About", command=self.show_about)
63 |
64 | root.configure(menu=self.menu_bar)
65 |
66 | self.file_entry_label1 = tk.Label(
67 | root, text="Enter Input Folder Path:", bg="#eeeeee", anchor=tk.W
68 | )
69 | self.file_entry_label1.grid(
70 | padx=12,
71 | pady=(8, 0),
72 | ipadx=0,
73 | ipady=1,
74 | row=0,
75 | column=0,
76 | columnspan=4,
77 | sticky=tk.W + tk.E + tk.N + tk.S,
78 | )
79 |
80 | self.file_entry1 = tk.Entry(
81 | root,
82 | textvariable=self._folder_url1,
83 | bg="#fff",
84 | exportselection=0,
85 | relief=tk.FLAT,
86 | )
87 | self.file_entry1.grid(
88 | padx=15,
89 | pady=6,
90 | ipadx=8,
91 | ipady=8,
92 | row=1,
93 | column=0,
94 | columnspan=4,
95 | sticky=tk.W + tk.E + tk.N + tk.S,
96 | )
97 |
98 | self.select_btn1 = tk.Button(
99 | root,
100 | text="SELECT INPUT FOLDER",
101 | command=self.selectfolder1_callback,
102 | width=42,
103 | bg="#3498db",
104 | fg="#ffffff",
105 | bd=2,
106 | relief=tk.FLAT,
107 | )
108 | self.select_btn1.grid(
109 | padx=15,
110 | pady=8,
111 | ipadx=24,
112 | ipady=6,
113 | row=2,
114 | column=0,
115 | columnspan=4,
116 | sticky=tk.W + tk.E + tk.N + tk.S,
117 | )
118 |
119 | self.file_entry_label2 = tk.Label(
120 | root, text="Enter Output Folder Path:", bg="#eeeeee", anchor=tk.W
121 | )
122 | self.file_entry_label2.grid(
123 | padx=12,
124 | pady=(8, 0),
125 | ipadx=0,
126 | ipady=1,
127 | row=3,
128 | column=0,
129 | columnspan=4,
130 | sticky=tk.W + tk.E + tk.N + tk.S,
131 | )
132 |
133 | self.file_entry2 = tk.Entry(
134 | root,
135 | textvariable=self._folder_url2,
136 | bg="#fff",
137 | exportselection=0,
138 | relief=tk.FLAT,
139 | )
140 | self.file_entry2.grid(
141 | padx=15,
142 | pady=6,
143 | ipadx=8,
144 | ipady=8,
145 | row=4,
146 | column=0,
147 | columnspan=4,
148 | sticky=tk.W + tk.E + tk.N + tk.S,
149 | )
150 |
151 | self.select_btn2 = tk.Button(
152 | root,
153 | text="SELECT OUTPUT FOLDER",
154 | command=self.selectfolder2_callback,
155 | width=42,
156 | bg="#3498db",
157 | fg="#ffffff",
158 | bd=2,
159 | relief=tk.FLAT,
160 | )
161 | self.select_btn2.grid(
162 | padx=15,
163 | pady=8,
164 | ipadx=24,
165 | ipady=6,
166 | row=5,
167 | column=0,
168 | columnspan=4,
169 | sticky=tk.W + tk.E + tk.N + tk.S,
170 | )
171 |
172 | self.key_entry_label = tk.Label(
173 | root, text="Enter Your API Key:", bg="#eeeeee", anchor=tk.W
174 | )
175 | self.key_entry_label.grid(
176 | padx=12,
177 | pady=(8, 0),
178 | ipadx=0,
179 | ipady=1,
180 | row=6,
181 | column=0,
182 | columnspan=4,
183 | sticky=tk.W + tk.E + tk.N + tk.S,
184 | )
185 |
186 | self.key_entry = tk.Entry(
187 | root,
188 | textvariable=self._api_key,
189 | bg="#fff",
190 | exportselection=0,
191 | relief=tk.FLAT,
192 | )
193 | self.key_entry.grid(
194 | padx=15,
195 | pady=6,
196 | ipadx=8,
197 | ipady=8,
198 | row=7,
199 | column=0,
200 | columnspan=4,
201 | sticky=tk.W + tk.E + tk.N + tk.S,
202 | )
203 |
204 | self.compress_btn = tk.Button(
205 | root,
206 | text="START COMPRESS",
207 | command=self.compress_callback,
208 | bg="#27ae60",
209 | fg="#ffffff",
210 | bd=2,
211 | relief=tk.FLAT,
212 | )
213 | self.compress_btn.grid(
214 | padx=15,
215 | pady=8,
216 | ipadx=24,
217 | ipady=6,
218 | row=8,
219 | column=0,
220 | columnspan=2,
221 | sticky=tk.W + tk.E + tk.N + tk.S,
222 | )
223 |
224 | self.stop_btn = tk.Button(
225 | root,
226 | text="STOP",
227 | command=self.stop_callback,
228 | bg="#aaaaaa",
229 | fg="#ffffff",
230 | bd=2,
231 | state="disabled",
232 | relief=tk.FLAT,
233 | )
234 | self.stop_btn.grid(
235 | padx=15,
236 | pady=8,
237 | ipadx=24,
238 | ipady=6,
239 | row=8,
240 | column=2,
241 | columnspan=2,
242 | sticky=tk.W + tk.E + tk.N + tk.S,
243 | )
244 |
245 | self.reset_btn = tk.Button(
246 | root,
247 | text="CLEAR STATUS",
248 | command=self.reset_callback,
249 | bg="#717d7e",
250 | fg="#ffffff",
251 | bd=2,
252 | relief=tk.FLAT,
253 | )
254 | self.reset_btn.grid(
255 | padx=15,
256 | pady=(4, 12),
257 | ipadx=24,
258 | ipady=6,
259 | row=9,
260 | column=0,
261 | columnspan=4,
262 | sticky=tk.W + tk.E + tk.N + tk.S,
263 | )
264 |
265 | self.status_label = tk.Label(
266 | root,
267 | textvariable=self._status,
268 | bg="#eeeeee",
269 | anchor=tk.W,
270 | justify=tk.LEFT,
271 | relief=tk.FLAT,
272 | wraplength=350,
273 | )
274 | self.status_label.grid(
275 | padx=12,
276 | pady=(0, 12),
277 | ipadx=0,
278 | ipady=1,
279 | row=10,
280 | column=0,
281 | columnspan=4,
282 | sticky=tk.W + tk.E + tk.N + tk.S,
283 | )
284 |
285 | def selectfolder1_callback(self):
286 | try:
287 | name = filedialog.askdirectory()
288 | self._folder_url1.set(name)
289 | except Exception as e:
290 | self._status.set(e)
291 | self.status_label.update()
292 |
293 | def selectfolder2_callback(self):
294 | try:
295 | name = filedialog.askdirectory()
296 | self._folder_url2.set(name)
297 | except Exception as e:
298 | self._status.set(e)
299 | self.status_label.update()
300 |
301 | def enable(self):
302 |
303 | self.stop_btn["bg"] = "#aaaaaa"
304 | self.stop_btn["state"] = "disabled"
305 | self.compress_btn["state"] = "normal"
306 | self.compress_btn["bg"] = "#27ae60"
307 | self.reset_btn["bg"] = "#717d7e"
308 | self.reset_btn["state"] = "normal"
309 | self.file_entry1["state"] = "normal"
310 | self.file_entry2["state"] = "normal"
311 | self.select_btn1["state"] = "normal"
312 | self.select_btn2["state"] = "normal"
313 | self.select_btn1["bg"] = "#3498db"
314 | self.select_btn2["bg"] = "#3498db"
315 |
316 | def disable(self):
317 |
318 | self.compress_btn["bg"] = "#aaaaaa"
319 | self.compress_btn["state"] = "disabled"
320 | self.reset_btn["bg"] = "#aaaaaa"
321 | self.reset_btn["state"] = "disabled"
322 | self.stop_btn["bg"] = "#e74c3c"
323 | self.stop_btn["state"] = "normal"
324 | self.file_entry1["state"] = "disabled"
325 | self.file_entry2["state"] = "disabled"
326 | self.select_btn1["state"] = "disabled"
327 | self.select_btn2["state"] = "disabled"
328 | self.select_btn1["bg"] = "#aaaaaa"
329 | self.select_btn2["bg"] = "#aaaaaa"
330 |
331 | def show_help_callback(self):
332 | messagebox.showinfo(
333 | "Help!",
334 | """1. Click SELECT INPUT FOLDER Button to select the INPUT FOLDER which contains all the Images to be Compressed/Optimized.
335 | 2. Click SELECT OUTPUT FOLDER Button to select the OUTPUT FOLDER which will contain all the the Compressed/Optimized Images. (After Compression)
336 | 3. Enter Your API Key from TINYPNG Website. If you don't have one in possession then you can find on this website https://tinypng.com/developers/
337 | 4. Hit the COMPRESS Button and the INPUT FOLDER containing Supported Image Formats will be Compressed and saved in the OUTPUT FOLDER.
338 | 5. Click CLEAR Button to reset the input fields and status bar. (If needed)
339 |
340 | NOTE: Recommended to keep INPUT and OUTPUT Folder different for your ease to differentiate between Optimized and Unoptimized Images.
341 | NOTE: Directory Structure in INPUT and OUTPUT Folders may differ but all Supported Images will be saved according to their directories.""",
342 | )
343 |
344 | def show_about(self):
345 | messagebox.showinfo(
346 | "Compresssio v2.1.0",
347 | """Compresssio is an Image Compression Tool which uses TinyPNG's lossy compression to compress JPG/JPEG/PNG images.
348 | Created and Managed by Dhruv Panchal & Urvesh Patel.
349 | https://github.com/dhhruv
350 | """,
351 | )
352 |
353 | def stop_callback(self):
354 | if not self.stopFlag:
355 | self.stopFlag = True
356 | self.stop = threading.Thread(
357 | target=self.stop_execute, name="Stopping_Thread", daemon=True
358 | )
359 | self.stop.start()
360 |
361 | def stop_execute(self):
362 | self.stop_btn["text"] = "STOPPING..." # Set button text to stoping.
363 | self._status.set("Stopping the Compression. Please Wait...")
364 | self.status_label.update()
365 |
366 | while self.stopFlag:
367 | time.sleep(1)
368 |
369 | self.stop_btn["text"] = "STOP"
370 | self._status.set("Compression Cancelled!!")
371 | self.status_label.update()
372 | self.enable()
373 | messagebox.showinfo("Compresssio", "Compression Cancelled!!")
374 |
375 | def compress_callback(self):
376 | self.disable()
377 | self.compress = threading.Thread(
378 | target=self.compress_execute, name="Compression_Thread", daemon=True
379 | )
380 | self.compress.start()
381 |
382 | def compress_execute(self):
383 | try:
384 |
385 | tinify.key = self._api_key.get()
386 | tinify.validate()
387 |
388 | self._status.set("Calculating Raw Images...")
389 | self.status_label.update()
390 |
391 | self.raw_images = get_raw_images(self._folder_url1.get())
392 | if not self.raw_images:
393 | self._status.set("No images found within supported formats!!!")
394 | self.status_label.update()
395 | messagebox.showinfo(
396 | "Compresssio",
397 | "No images found within supported formats. Please check the INPUT Folder and Try Again!!!",
398 | )
399 | self.reset_callback()
400 | else:
401 | create_dirs(self.raw_images, self._folder_url2.get())
402 |
403 | self._status.set("Compression in Progress....")
404 | self.status_label.update()
405 | length = len(self.raw_images)
406 |
407 | for (index, image) in enumerate(self.raw_images):
408 | if self.stopFlag:
409 | self.stopFlag = False
410 | return
411 |
412 | (only_image_path, image_info) = os.path.split(image)
413 | self._status.set(
414 | "Compressing Image [{}/{}] : {}".format(
415 | index + 1, length, image_info
416 | )
417 | )
418 | self.status_label.update()
419 | change_dir(image, self._folder_url1.get(), self._folder_url2.get())
420 | compress_and_save(self._folder_url1.get() + "/" + image)
421 | self._status.set("Compression Completed !!")
422 | self.status_label.update()
423 | self.stopFlag = False
424 | self.enable()
425 | messagebox.showinfo("Compresssio", "Compression Completed !!")
426 | except tinify.AccountError:
427 |
428 | messagebox.showinfo(
429 | "AccountError", "Please verify your Tinify API key and account limit..."
430 | )
431 | except tinify.ClientError:
432 | messagebox.showinfo("ClientError", "Please check your source images...")
433 | except tinify.ServerError:
434 | messagebox.showinfo(
435 | "ServerError",
436 | """Temporary issue with the Tinify API.
437 | Please try again later...""",
438 | )
439 | except tinify.ConnectionError:
440 | messagebox.showinfo(
441 | "ConnectionError",
442 | """A network connection error occurred.
443 | Please check your Internet Connection and Try again...""",
444 | )
445 | except Exception as e:
446 | messagebox.showinfo(
447 | "UnknownError", "Something went wrong. Please try again later..."
448 | )
449 | self.enable()
450 |
451 | def reset_callback(self):
452 | self._folder_url1.set("")
453 | self._folder_url2.set("")
454 | self._status.set("---")
455 | self.stopFlag = False
456 |
457 |
458 | bundle_dir = getattr(sys, "_MEIPASS", os.path.abspath(os.path.dirname(__file__)))
459 | path_to_ico = os.path.abspath(os.path.join(bundle_dir, "./files/compresssio.ico"))
460 | ROOT = tk.Tk()
461 | ROOT.resizable(height=False, width=False)
462 | folder_path_1 = StringVar()
463 | folder_path_2 = StringVar()
464 | MAIN_WINDOW = MainWindow(ROOT)
465 | ROOT.iconbitmap(path_to_ico)
466 | ROOT.mainloop()
467 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 Dhruv Panchal
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 |
Streamline/Optimize your Images to save storage space...
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 | # Compresssio:
19 |
20 | The above script uses TinyPNG's savvy lossy compression methods to reduce the document size of your JPG/PNG files. This is achieved by specifically decreasing the number of colors in the image, therefore lesser number of bytes are required to store the information. The impact of the script is nearly invisible but it makes an exceptionally enormous effect in file size of the image.
21 |
22 | ## Image Comparison:
23 |
24 |
25 |
Image 1:
26 |
27 |
28 |
29 |
30 |
Image 2:
31 |
32 |
33 |
34 | ## Setup (Windows):
35 |
36 | 1. Install Python
37 | 2. Clone this repository
38 | ```
39 | git clone https://github.com/dhhruv/Compresssio-GUI.git
40 | ```
41 |
42 | 3. Install, create and activate virtual environment.
43 | For instance we create a virtual environment named 'venv'.
44 | ```
45 | pip install virtualenv
46 | python -m virtualenv venv
47 | venv\Scripts\activate.bat
48 | ```
49 |
50 | 4. Install dependencies
51 | ```
52 | pip install -r requirements.txt
53 | ```
54 |
55 |
56 |
57 |
58 |
59 |
60 | ## How to Get Your API Key !
61 |
62 | You can Find your API Key from the Website [https://tinypng.com/developers](https://tinypng.com/developers) after Signing Up and save it somewhere on your PC/Laptop.
63 |
64 |
65 | ## How To Use !
66 | 1. Click SELECT INPUT FOLDER Button to select the INPUT FOLDER which contains all the Images to be Compressed/Optimized.
67 | 2. Click SELECT OUTPUT FOLDER Button to select the OUTPUT FOLDER which will contain all the the Compressed/Optimized Images. (After Compression)
68 | 3. Enter Your API Key from TINYPNG Website. If you don't have one in possession then you can find on this website https://tinypng.com/developers .
69 | 4. Hit the COMPRESS Button and the INPUT FOLDER containing Supported Image Formats will be Compressed and saved in the OUTPUT FOLDER.
70 | 5. Click CLEAR Button to reset the input fields and status bar. (If needed)
71 |
72 | ## Important Note:
73 |
74 | - **The limit you'll have at first is of 500 images per month on the Free plan. You can change this according to your requirement at [https://tinypng.com/developers](https://tinypng.com/developers)**
75 | - **Recommended to keep INPUT and OUTPUT Folder different for your ease to differentiate between Optimized and Unoptimized Images.**
76 | - **This Script is just a Prototype so Metadata is not stored in the Compressed Images from the Original Images.**
77 | - **Directory Structure in INPUT and OUTPUT Folders may differ but all Supported Images will be saved according to their directories.**
78 | - **The Authors will not be responsible for any kind of loss of data so it is essential to have a Backup of Original Data placed in the Input Folder. Read the [LICENSE](https://github.com/dhhruv/Compresssio-GUI/blob/master/LICENSE) for more information.**
79 |
80 | ## Contributors:
81 |
82 |
83 |
84 |
85 |
86 | ## Image Credits:
87 | - [Unsplash](https://unsplash.com/)
88 |
89 |
--------------------------------------------------------------------------------
/files/compresssio.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dhhruv/Compresssio-GUI/80465305c5d1d863abd0698b4f3d5ead3ce64dba/files/compresssio.ico
--------------------------------------------------------------------------------
/files/compresssio.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dhhruv/Compresssio-GUI/80465305c5d1d863abd0698b4f3d5ead3ce64dba/files/compresssio.png
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | tinify==1.5.1
2 | urllib3==1.26.5
3 | certifi==2020.11.8
4 | idna==2.10
5 | chardet==3.0.4
6 | requests==2.25.0
--------------------------------------------------------------------------------
/settings.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python
2 | # -*- coding: utf-8 -*-
3 |
4 | import os
5 | import os.path
6 | from tkinter import messagebox
7 | import shutil
8 | import sys
9 | import tinify
10 |
11 | SUPPORTED_FORMATS = ("jpg", "jpeg", "png")
12 |
13 |
14 | def create_dirs(raw_images, save_dir):
15 | for image in raw_images:
16 | compress_dir = save_dir + "/" + os.path.dirname(image)
17 | if not os.path.isdir(compress_dir):
18 | os.makedirs(compress_dir)
19 |
20 |
21 | def get_raw_images(raw_images_dir):
22 |
23 | if not os.path.isdir(raw_images_dir):
24 | messagebox.showinfo(
25 | "Directory Error !",
26 | """Input Folder Does not Exist.
27 | Please Check the Directory and Try Again""",
28 | )
29 |
30 | raw_images = []
31 |
32 | for (root, directories, files) in os.walk(raw_images_dir):
33 | for filename in files:
34 | if not filename.startswith("."):
35 | file_type = filename.split(".")[-1].lower()
36 | if file_type in SUPPORTED_FORMATS:
37 | filepath = os.path.join(root, filename)
38 | raw_images.append(filepath.replace(raw_images_dir, ""))
39 |
40 | return raw_images
41 |
42 |
43 | def change_dir(abs_image_path, raw_images_dir, save_dir):
44 | custom_dir_path = os.path.dirname(abs_image_path)
45 | custom_dir_path = custom_dir_path.split("\\")
46 | compressed_custom_dir_path = save_dir + "/" + "/".join(custom_dir_path)
47 | os.chdir(compressed_custom_dir_path)
48 |
49 |
50 | def compress_and_save(abs_image_path):
51 |
52 | (only_image_path, image_info) = os.path.split(abs_image_path)
53 |
54 | index = image_info.rindex(".")
55 | (image_name, image_type) = (image_info[:index], image_info[index + 1 :])
56 | optimized_filename = "{}_optimized.{}".format(image_name, image_type)
57 | if not os.path.isfile(optimized_filename):
58 | source = tinify.from_file(abs_image_path)
59 | source.to_file(optimized_filename)
60 |
--------------------------------------------------------------------------------