-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbulk_resizer_lite.py
More file actions
115 lines (85 loc) Β· 3.52 KB
/
bulk_resizer_lite.py
File metadata and controls
115 lines (85 loc) Β· 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import time
from PIL import Image
# -------------------------
# LITE VERSION LIMITS
# -------------------------
MAX_IMAGES = 5 # Max images per batch
MAX_USES = 3 # Total number of allowed runs
DELAY_PER_IMAGE = 3 # Seconds delay per image
USAGE_FILE = ".lite_usage_count"
# -------------------------
INPUT_FOLDER = "input_images"
OUTPUT_FOLDER = "optimized_images"
TARGET_WIDTH = 1080
QUALITY = 85
def get_usage_count():
"""Read usage count from hidden file."""
if not os.path.exists(USAGE_FILE):
return 0
try:
with open(USAGE_FILE, "r") as f:
return int(f.read().strip())
except:
return 0
def increment_usage_count():
"""Increase usage count by 1."""
count = get_usage_count() + 1
with open(USAGE_FILE, "w") as f:
f.write(str(count))
return count
def check_usage_limit():
"""Check and enforce max usage limit."""
count = get_usage_count()
if count >= MAX_USES:
print("\nβ LITE VERSION LIMIT REACHED")
print("You have used the free version 3 times.")
print("Unlock unlimited images & fast processing here:")
print("π https://anshika636.gumroad.com/l/image-tool\n")
input("Press Enter to exit...")
exit()
new_count = increment_usage_count()
print(f"\nπΉ Lite version use: {new_count}/{MAX_USES} allowed.\n")
def resize_images():
check_usage_limit()
# Create output folder if needed
if not os.path.exists(OUTPUT_FOLDER):
os.makedirs(OUTPUT_FOLDER)
# Check input folder
if not os.path.exists(INPUT_FOLDER):
print(f"Error: Folder '{INPUT_FOLDER}' not found.")
return
images = [f for f in os.listdir(INPUT_FOLDER)
if f.lower().endswith(('.png', '.jpg', '.jpeg'))]
if not images:
print("No images found in input_images/")
return
print(f"Found {len(images)} images.")
if len(images) > MAX_IMAGES:
print(f"\nβ LITE VERSION: Only first {MAX_IMAGES} images will be processed.")
print("π Full version (unlimited images): https://anshika636.gumroad.com/l/image-tool\n")
images = images[:MAX_IMAGES]
print(f"Starting optimization for {len(images)} image(s)...\n")
for img_name in images:
try:
img_path = os.path.join(INPUT_FOLDER, img_name)
with Image.open(img_path) as img:
aspect_ratio = img.height / img.width
new_height = int(TARGET_WIDTH * aspect_ratio)
img = img.resize((TARGET_WIDTH, new_height), Image.Resampling.LANCZOS)
# Add watermark suffix
output_name = img_name.rsplit('.', 1)[0] + "_LITE." + img_name.rsplit('.', 1)[1]
save_path = os.path.join(OUTPUT_FOLDER, output_name)
img.save(save_path, optimize=True, quality=QUALITY)
print(f"β Processed: {img_name} β {output_name}")
# Delay for lite version
print(f"β³ LITE version delay ({DELAY_PER_IMAGE}s)...")
time.sleep(DELAY_PER_IMAGE)
except Exception as e:
print(f"β Error: {e}")
print("\n--- LITE VERSION DONE ---")
print("β‘ Full version = instant processing + unlimited images + no watermark")
print("π https://anshika636.gumroad.com/l/image-tool")
input("\nPress Enter to exit...")
if __name__ == "__main__":
resize_images()