Commit e0eaaf86 authored by dovahkiin's avatar dovahkiin

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

parent 189d0b20
......@@ -262,9 +262,20 @@ 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:
# 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)
......@@ -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,13 +340,43 @@ 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.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.cobit:
layer_info_item.x = max_x
layer_info_item.y = max_y
......
......@@ -108,9 +108,13 @@ 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.Auto_cut_1:
info_prompt = "< | 智 能 切 割 | >"
else:
if psd_data.equal_size:
info_prompt += "需要等大|"
else:
......
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