이미지 파일 resize, rotate, hflip, vflip, rename

 

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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import sys
import os
from PyQt5.QtWidgets import *
from PyQt5.QtCore import Qt
from PIL import Image
 
class MyApp(QWidget):
 
    def __init__(self):
         super().__init__()
         self.initUI()
 
    def initUI(self):
        #QGridLayout
        grid = QGridLayout()
        self.setLayout(grid)
        
 
        #QCheckBox
        self.checkboxResize = QCheckBox('Resize', self)
        self.checkboxRotate = QCheckBox('Rotate', self)
        self.checkboxHflip = QCheckBox('Hflip', self)
        self.checkboxVflip = QCheckBox('Vflip', self)
        self.checkboxRename = QCheckBox('Rename', self)
        
#checkboxResize.stateChanged.connect(self.changeCheckBox)
#        checkboxRotate.stateChanged.connect(self.changeCheckBox)
#        checkboxHflip.stateChanged.connect(self.changeCheckBox)
#        checkboxVflip.stateChanged.connect(self.changeCheckBox)
#        checkboxRename.stateChanged.connect(self.changeCheckBox)
        
 
        #QLineEdit
        self.lineEditResize = QLineEdit(' ', self)
        self.lineEditRotate = QLineEdit(' ', self)
        self.lineEditPrefix = QLineEdit(' ', self)
        self.lineEditSuffix = QLineEdit(' ', self)
        self.lineEditPATH   = QLineEdit(' ', self)
    
 
        #QLabel
        labelPrefix = QLabel('Prefix', self)
        labelSuffix = QLabel('Suffix', self)
        labelNumber = QLabel('Number', self)
        labelPATH   = QLabel('PATH', self)
 
 
        #QPushButton
        self.pushButtonRUN = QPushButton('RUN', self)
        self.pushButtonRUN.clicked.connect(self.onButton)
 
        #gridWidget
        grid.addWidget(self.checkboxResize, 00)
        grid.addWidget(self.checkboxRotate, 10)
        grid.addWidget(self.checkboxHflip, 20)
        grid.addWidget(self.checkboxVflip, 30)
        grid.addWidget(self.checkboxRename, 40)
        
        grid.addWidget(self.lineEditResize, 01)
        grid.addWidget(self.lineEditRotate, 11)
        grid.addWidget(self.lineEditPrefix, 51)
        grid.addWidget(self.lineEditSuffix, 53)
        grid.addWidget(self.lineEditPATH,   6113)
        
        grid.addWidget(labelPrefix, 41)
        grid.addWidget(labelSuffix, 43)
        grid.addWidget(labelNumber, 52)
        grid.addWidget(labelPATH, 60)
 
        grid.addWidget(self.pushButtonRUN, 03)
 
 
        self.setWindowTitle('QCheckBox')
        self.setGeometry(500500500300)
        self.show()
 
    def changeCheckBox(self, state):
        if state == Qt.Checked:
            self.setWindowTitle('QCheckBox')
        else:
            self.setWindowTitle(' ')
 
    def onButton(self):
 
        path_text=self.lineEditPATH.text()
        path_text=path_text[1:]    
        
        print(path_text)
        im = Image.open(path_text)
 
        
        resize_tf=self.checkboxResize.isChecked()
        rotate_tf=self.checkboxRotate.isChecked()
        hflip_tf=self.checkboxHflip.isChecked()
        vflip_tf=self.checkboxVflip.isChecked()
        rename_tf=self.checkboxRename.isChecked()
        print(resize_tf)
        print(rotate_tf)
        print(hflip_tf)
        print(vflip_tf)
        print(rename_tf)
        if resize_tf==True:
            resize_num=self.lineEditResize.text()
#print(resize)
            resize_num=resize_num[1:]
            print(resize_num)
            resize_arr=resize_num.split(',')
            print(resize_arr[0],resize_arr[1])
            im=im.resize((int(resize_arr[0]),int(resize_arr[1])))
#    print("resize true")
        if rotate_tf==True:
            rotate_num=self.lineEditRotate.text()
            rotate_num=int(rotate_num)
            print(rotate_num)
            im=im.rotate(rotate_num)
            
 
        if hflip_tf==True:
            im=im.transpose(Image.FLIP_LEFT_RIGHT)
            print("hflip true")
 
 
        if vflip_tf==True:
            im=im.transpose(Image.FLIP_TOP_BOTTOM)
            print("vflip true")
 
        if rename_tf==True:
            im.save(path_text)
            im.show()
            path_text_arr=path_text.split('.')
            prefix_text=self.lineEditPrefix.text()
            suffix_text=self.lineEditSuffix.text()
            
            os.rename(path_text,prefix_text[1:]+'_'+path_text_arr[0]+'_'+suffix_text[1:]+'.'+path_text_arr[1])
            
            print("rename true")
            return 0
 
        im.show()
 
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = MyApp()
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

+ Recent posts