1
+ #iJ
2
+
3
+ from tkinter import filedialog
4
+ from tkinter import *
5
+ import tkinter
6
+ import os
7
+ from PIL import ImageTk , Image , ImageDraw
8
+
9
+ root = tkinter .Tk ()
10
+ root .title ("RMSpriter" )
11
+ root .geometry ("450x570" )
12
+ root .resizable (False ,False )
13
+ root .configure (bg = '#191919' )
14
+
15
+ rmxp_img = PhotoImage (file = r"img/rmxp.png" )
16
+ rmvx_img = PhotoImage (file = r"img/rmvx.png" )
17
+ frames_one_img = PhotoImage (file = r"img/frames1.png" )
18
+ frames_all_img = PhotoImage (file = r"img/frames2.png" )
19
+ output_img = PhotoImage (file = r"img/output.png" )
20
+
21
+ def workplace ():
22
+ global image , bigger_parameter
23
+ file_name = filedialog .askopenfilename (filetypes = [("Sprite" , ".png" )])
24
+
25
+ if file_name == "" :
26
+ workplace_button .config (text = "Click here to\n select a file" , image = "" , anchor = "center" )
27
+ convert_button ["state" ] = DISABLED
28
+ return
29
+
30
+ image = Image .open (file_name )
31
+
32
+ if (image .width >= 430 ) or (image .height >= 430 ):
33
+
34
+ if image .width <= image .height :
35
+ bigger_parameter = image .height
36
+
37
+ elif image .width >= image .height :
38
+ bigger_parameter = image .width
39
+
40
+ preview_width , preview_height = (image .width )// (bigger_parameter / 430 ), (image .height )// (bigger_parameter / 430 )
41
+ preview_image = image .resize ((int (preview_width ), int (preview_height )))
42
+ else :
43
+ preview_image = image
44
+
45
+ root .tkimage = ImageTk .PhotoImage (preview_image )
46
+ workplace_button .config (image = root .tkimage , anchor = "center" )
47
+ convert_button ["state" ] = NORMAL
48
+ return image
49
+
50
+ output_directory = (os .getcwd () + "/output.png" ).replace ("\\ " , "/" )
51
+ default_directory = output_directory
52
+ def output ():
53
+ global default_directory , output_directory
54
+ folder_selected = filedialog .askdirectory ()
55
+ output_directory = (folder_selected + "/output.png" )
56
+
57
+ if folder_selected == "" :
58
+ output_directory = default_directory
59
+
60
+ output_directory_label .config (text = (" " + output_directory ))
61
+ return output_directory
62
+
63
+ current_rpgmaker = "xp"
64
+ def rpgmaker ():
65
+ global current_rpgmaker
66
+
67
+ if current_rpgmaker == "xp" :
68
+ rpgmaker_button .config (text = "VX" )
69
+ current_rpgmaker = "vx"
70
+
71
+ elif current_rpgmaker == "vx" :
72
+ rpgmaker_button .config (text = "XP" )
73
+ current_rpgmaker = "xp"
74
+
75
+ return current_rpgmaker
76
+
77
+ current_frames = "one"
78
+ def frames ():
79
+ global current_frames
80
+
81
+ if current_frames == "one" :
82
+ frames_button .config (image = frames_all_img )
83
+ current_frames = "all"
84
+
85
+ elif current_frames == "all" :
86
+ frames_button .config (image = frames_one_img )
87
+ current_frames = "one"
88
+
89
+ return current_frames
90
+
91
+ def convert ():
92
+ global current_frames , current_rpgmaker , image , bigger_parameter
93
+ width , height = image .width , image .height
94
+
95
+ if current_rpgmaker == "xp" :
96
+ output = Image .new ('RGBA' , (width * 4 , height * 4 ), (255 , 0 , 0 , 0 ))
97
+ first_row = 4
98
+ second_row = 8
99
+ third_row = 12
100
+ loop_range = 17
101
+
102
+ elif current_rpgmaker == "vx" :
103
+ output = Image .new ('RGBA' , (width * 3 , height * 4 ), (255 , 0 , 0 , 0 ))
104
+ first_row = 3
105
+ second_row = 6
106
+ third_row = 9
107
+ loop_range = 13
108
+
109
+ draw = ImageDraw .Draw (output )
110
+ output .save (output_directory , 'PNG' )
111
+ bg = Image .open (output_directory )
112
+ fg = image
113
+ x = 0
114
+ y = 0
115
+
116
+ if current_frames == "one" :
117
+ bg .paste (fg , (x , y ), fg .convert ('RGBA' ))
118
+
119
+ if current_frames == "all" :
120
+
121
+ for i in range (1 , loop_range ):
122
+ bg .paste (fg , (x , y ), fg .convert ('RGBA' ))
123
+ x = x + width
124
+
125
+ if (i == first_row ) or (i == second_row ) or (i == third_row ):
126
+ x = 0
127
+ y = y + height
128
+
129
+ bg .save (output_directory )
130
+ output_image = Image .open (output_directory )
131
+
132
+ if (output_image .width >= 430 ) or (output_image .height >= 430 ):
133
+
134
+ if output_image .width <= output_image .height :
135
+ bigger_parameter = output_image .height
136
+
137
+ elif output_image .width >= output_image .height :
138
+ bigger_parameter = output_image .width
139
+
140
+ output_width , output_height = (output_image .width )// (bigger_parameter / 430 ), (output_image .height )// (bigger_parameter / 430 )
141
+ output_image = output_image .resize ((int (output_width ), int (output_height )))
142
+
143
+ root .tkimage = ImageTk .PhotoImage (output_image )
144
+ workplace_button .config (image = root .tkimage , anchor = "center" )
145
+ convert_button ["state" ] = NORMAL
146
+
147
+ rpgmaker_button = tkinter .Button (root , compound = "c" , relief = "solid" , bg = "#393939" , activebackground = "#393939" , activeforeground = "white" , fg = "white" , text = "XP" , font = ("Bahnschrift" , 20 , "bold" ), command = rpgmaker )
148
+ rpgmaker_button .place (x = 10 , y = 10 , height = 50 , width = 50 )
149
+
150
+ output_button = tkinter .Button (root , compound = "c" , relief = "solid" , bg = "#393939" , activebackground = "#393939" , activeforeground = "white" , image = output_img , command = output )
151
+ output_button .place (x = 390 , y = 10 ,height = 50 , width = 50 )
152
+
153
+ frames_button = tkinter .Button (root , compound = "c" , relief = "solid" , bg = "#393939" , activebackground = "#393939" , activeforeground = "white" , image = frames_one_img , command = frames )
154
+ frames_button .place (x = 10 , y = 70 , height = 50 , width = 50 )
155
+
156
+ convert_button = tkinter .Button (root , compound = "c" , relief = "solid" , bg = "#393939" , fg = "white" , activebackground = "#393939" , activeforeground = "white" , state = DISABLED , text = "CONVERT" , font = ("Bahnschrift" , 20 , "bold" ), command = convert )
157
+ convert_button .place (x = 70 , y = 70 ,height = 50 , width = 370 )
158
+
159
+ workplace_button = tkinter .Button (root , bd = 2 , anchor = "center" , relief = "solid" , bg = "#393939" , fg = "white" , activebackground = "#393939" , activeforeground = "white" , text = "Click here to\n select a file" , font = ("Bahnschrift" , 30 , "bold" ), command = workplace )
160
+ workplace_button .place (x = 10 , y = 130 ,height = 430 , width = 430 )
161
+
162
+ output_directory_label = Label (root , bd = 2 , anchor = "w" , relief = "solid" , bg = "#393939" , fg = "white" , text = (" " + output_directory ), font = ("Bahnschrift" , 13 , "bold" ))
163
+ output_directory_label .place (x = 70 , y = 10 ,height = 50 , width = 321 )
164
+
165
+ root .mainloop ()
0 commit comments