Skip to content
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

Batch processing script to prompt for folders, watermark text, type, method. #38

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
58 changes: 58 additions & 0 deletions adev_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import os
import subprocess
from tkinter import filedialog
from tkinter import Tk

def select_folder(prompt):
root = Tk()
root.withdraw()
folder_path = filedialog.askdirectory(title=prompt)
root.destroy()
return folder_path

def get_user_inputs():
action = input("Enter the action (encode or decode): ").strip()
watermark_type = input("Enter the watermark type (bytes, b16, bits, uuid, ipv4): ").strip()
method = input("Enter the encoding/decoding method (dwtDct, dwtDctSvd, rivaGan): ").strip()
watermark_text = ""
length = ""
if action == "encode":
watermark_text = input("Enter the watermark text: ").strip()
elif action == "decode" and watermark_type in ["bytes", "b16", "bits"]:
length = input("Enter the length of watermark bits: ").strip()
return action, watermark_type, method, watermark_text, length

input_folder = select_folder("Select the folder containing the images to watermark or decode")
action, watermark_type, method, watermark_text, length = get_user_inputs()
if action == "encode":

output_folder = select_folder("Select the folder to save the processed images")

invisible_watermark_script_path = "invisible-watermark.py"

for filename in os.listdir(input_folder):
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.bmp')):
input_path = os.path.join(input_folder, filename)
command = [
"python", invisible_watermark_script_path, "-v",
"-a", action,
"-t", watermark_type,
"-m", method
]
if action == "encode":
output_filename = os.path.splitext(filename)[0] + "_processed" + os.path.splitext(filename)[1]
output_path = os.path.join(output_folder, output_filename)
command.extend(["-w", watermark_text, "-o", output_path])
elif action == "decode" and length:
command.extend(["-l", length])
command.append(input_path)
try:
result = subprocess.run(command, check=True, capture_output=True, text=True)
if action == "decode":
print(f"Decoded watermark from {filename}: {result.stdout.strip()}")
else:
print(f"Successfully processed: {filename}")
except subprocess.CalledProcessError as e:
print(f"Failed to process: {filename}, Error: {str(e)}")

print("All images have been processed.")
File renamed without changes.