-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestScript
73 lines (55 loc) · 2.42 KB
/
TestScript
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
import tkinter as tk
from tkinter import filedialog
from PIL import Image
import numpy as np
import imageio
import os
def convert_to_dds(input_path, output_path, target_size=(1024, 1024)):
# Open the image using Pillow
img = Image.open(input_path)
# Check if resizing is needed
if img.size[0] > target_size[0] or img.size[1] > target_size[1]:
img = img.resize(target_size, Image.ANTIALIAS)
# Convert the image to a NumPy array
img_array = np.array(img)
# Save the resized image to a temporary file
temp_output_path = "temp_resized.png"
imageio.imwrite(temp_output_path, img_array)
# Convert the temporary image to DDS with DXT1 compression using imageio
imageio.plugins.freeimage.download()
imageio.plugins.freeimage.get_freeimage()
imageio.plugins.freeimage.write_dxt(temp_output_path, output_path)
# Remove the temporary file
os.remove(temp_output_path)
def browse_file():
filename = filedialog.askopenfilename(initialdir="/", title="Select File",
filetypes=(("Image files", "*.png;*.jpg;*.jpeg;*.bmp;*.gif"),
("all files", "*.*")))
entry_path.delete(0, tk.END)
entry_path.insert(0, filename)
def convert_image():
input_path = entry_path.get()
if not os.path.isfile(input_path):
status_label.config(text="Invalid file path", fg="red")
return
output_path = filedialog.asksaveasfilename(defaultextension=".dds", filetypes=(("DDS files", "*.dds"), ("all files", "*.*")))
if not output_path:
return # User canceled save dialog
convert_to_dds(input_path, output_path)
status_label.config(text="Conversion successful", fg="green")
# Create the main application window
app = tk.Tk()
app.title("Image Converter")
# Create and place widgets in the window
label_path = tk.Label(app, text="Input Image:")
label_path.grid(row=0, column=0, padx=10, pady=10)
entry_path = tk.Entry(app, width=50)
entry_path.grid(row=0, column=1, padx=10, pady=10)
button_browse = tk.Button(app, text="Browse", command=browse_file)
button_browse.grid(row=0, column=2, padx=10, pady=10)
button_convert = tk.Button(app, text="Convert", command=convert_image)
button_convert.grid(row=1, column=1, pady=20)
status_label = tk.Label(app, text="", fg="black")
status_label.grid(row=2, column=0, columnspan=3, pady=10)
# Start the application event loop
app.mainloop()