Commit e0eaaf86 authored by dovahkiin's avatar dovahkiin

添加智能切割部分,切割图片代码

parent 189d0b20
......@@ -262,22 +262,33 @@ def extractLayerImge(lay_info:lay_item, psd_name:str, lwdtI:QListWidgetItem):
try:
if lay_info.w != 0 or lay_info.h != 0:
if lay_info.Auto_cut_1:
pass
else:
layer_image = psd.composite(viewport = pos, force=True)
# if lay_info.Auto_cut_1:
# for info in auto_cut_info.keys():
# break_flag = False
# for data_i in auto_cut_info[info]:
# if data_i == lay_info:
# x1 = info[0] - info[2]//2
# y1 = info[1] - info[3]//2
# x2 = x1 + info[2]
# y2 = y1 + info[3]
# pos = (x1, y1, x2, y2)
# if break_flag :
# break
# else:
layer_image = psd.composite(viewport = pos, force=True)
# layer_image.show(layer_name)
# print("[# layer_image #]:", layer_image, "xywh:", xywh)
# temp_psd_show = psd.compose(True)
# temp_psd_show.show()
if lay_info.show:
layer_image.show()
folder = os.path.exists(psd_name[:-4])
if not folder: #判断是否存在文件夹如果不存在则创建为文件夹
os.makedirs(psd_name[:-4])
layer_image.save(layer_name)
lay_info.layer.visible = False
if lay_info.show:
layer_image.show()
folder = os.path.exists(psd_name[:-4])
if not folder: #判断是否存在文件夹如果不存在则创建为文件夹
os.makedirs(psd_name[:-4])
layer_image.save(layer_name)
lay_info.layer.visible = False
# {}[0]
except KeyError:
color = QColor(220, 220, 41)
......@@ -298,6 +309,7 @@ def get_lay_info(psd_info:flag_data):
max_w = max_h = 0
max_x = max_y= -1
layer_list = []
auto_cut_info = {}
for layer in psd.descendants():
if layer.is_group():
......@@ -328,29 +340,59 @@ def get_lay_info(psd_info:flag_data):
# temp_psd_show = psd.compose(True)
# temp_psd_show.show()
# print(auto_cut_infor)
for info_i in auto_cut_info.keys():
print(info_i)
max_info_w = max_info_h = 0
# 获取不同的中心点下坐标的宽高
for info_i in list(auto_cut_info.keys()):
for data_i in auto_cut_info[info_i]:
print("\t", data_i)
if max_info_w < data_i.width:
max_info_w = data_i.width
if max_info_h < data_i.height:
max_info_h = data_i.height
auto_cut_info[(info_i[0], info_i[1], max_info_w+1 if max_info_w%2 else max_info_w, max_info_h+1 if max_info_h%2 else max_info_h)]= auto_cut_info[info_i]
del auto_cut_info[info_i]
max_info_w = max_info_h = 0
# for info_i in auto_cut_info.keys():
# print(info_i)
# for data_i in auto_cut_info[info_i]:
# print("\t", data_i)
layer_info_list:list[lay_item] = []
for layer in layer_list:
layer_info_item = lay_item()
if psd_info.cobit:
layer_info_item.x = max_x
layer_info_item.y = max_y
layer_info_item.w = max_w + 1 if max_w % 2 else max_w
layer_info_item.h = max_h + 1 if max_h % 2 else max_h
if psd_info.Auto_cut_1:
max_w = max_h = 0
max_x = max_y= -1
for info in auto_cut_info.keys():
break_flag = False
for data_i in auto_cut_info[info]:
if data_i == layer:
layer_info_item.x = info[0] - info[2]//2
layer_info_item.y = info[1] - info[3]//2
layer_info_item.w = info[2]
layer_info_item.h = info[3]
break_flag = True
break
if break_flag :
break
else:
if psd_info.equal_size:
if psd_info.cobit:
layer_info_item.x = max_x
layer_info_item.y = max_y
layer_info_item.w = max_w + 1 if max_w % 2 else max_w
layer_info_item.h = max_h + 1 if max_h % 2 else max_h
else:
layer_info_item.w = layer.width + 1 if layer.width % 2 else layer.width
layer_info_item.h = layer.height + 1 if layer.height % 2 else layer.height
layer_info_item.x = layer.left
layer_info_item.y = layer.top
if psd_info.equal_size:
layer_info_item.w = max_w + 1 if max_w % 2 else max_w
layer_info_item.h = max_h + 1 if max_h % 2 else max_h
else:
layer_info_item.w = layer.width + 1 if layer.width % 2 else layer.width
layer_info_item.h = layer.height + 1 if layer.height % 2 else layer.height
layer_info_item.x = layer.left
layer_info_item.y = layer.top
layer_info_item.layer_name = layer.name
layer_info_item.layer = layer
print(layer_info_item)
......
......@@ -108,25 +108,29 @@ class Pyqt5_Cut_psd(QtWidgets.QMainWindow, Ui_Form):
psd_data.cobit = self.cbx_equal_position.isChecked()
psd_data.show = self.cbx_show.isChecked()
psd_data.equal_size = self.cbx_equal_size.isChecked()
psd_data.Auto_cut_1 = self.cbx_auto_1.isChecked()
self.lib_info_data.clear()
info_prompt = "<" + psd_name + "|"
if psd_data.equal_size:
info_prompt += "需要等大|"
if psd_data.Auto_cut_1:
info_prompt = "< | 智 能 切 割 | >"
else:
info_prompt += "无需等大|"
if psd_data.english:
info_prompt += "需要转化成英语|"
else:
info_prompt += "不要转化成英语|"
if psd_data.cobit:
info_prompt += "需要共位|"
else:
info_prompt += "无需共位|"
if psd_data.show:
info_prompt += "需要显示>"
else:
info_prompt += "无需显示>"
if psd_data.equal_size:
info_prompt += "需要等大|"
else:
info_prompt += "无需等大|"
if psd_data.english:
info_prompt += "需要转化成英语|"
else:
info_prompt += "不要转化成英语|"
if psd_data.cobit:
info_prompt += "需要共位|"
else:
info_prompt += "无需共位|"
if psd_data.show:
info_prompt += "需要显示>"
else:
info_prompt += "无需显示>"
self.lib_info_data.setText(info_prompt)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment