def beauty_file(): img_list = globalvar.get_value('img_list_global') src = img_list[len(img_list) - 1].convert('RGB') src = np.array(src) dst = np.zeros_like(src) # int value1 = 3, value2 = 1; 磨皮程度与细节程度的确定 v1 = 3 v2 = 1 dx = v1 * 5 # 双边滤波参数之一 fc = v1 * 12.5 # 双边滤波参数之一 p = 0.1 temp4 = np.zeros_like(src) temp1 = cv2.bilateralFilter(src, dx, fc, fc) temp2 = cv2.subtract(temp1, src) temp2 = cv2.add(temp2, (10, 10, 10, 128)) temp3 = cv2.GaussianBlur(temp2, (2 * v2 - 1, 2 * v2 - 1), 0) temp4 = cv2.subtract(cv2.add(cv2.add(temp3, temp3), src), (10, 10, 10, 255)) dst = cv2.addWeighted(src, p, temp4, 1 - p, 0.0) dst = cv2.add(dst, (10, 10, 10, 255)) show_img = Image.fromarray(dst) img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def water_file(): img_list = globalvar.get_value('img_list_global') show_img = img_list[len(img_list) - 1].convert('RGBA') # 转化为RGBA模式 # 1.创建一张透明的图片,在透明图片上写上字,然后与原图合并 w, h = show_img.size water = Image.new('RGBA', (w, h), (0, 0, 0, 0)) fn_size = 100 fn_str = g.enterbox(msg='请输入文字', title='水印文字设置', default='') if len(fn_str) == 0: fn_str = 'watermark' fn = ImageFont.truetype(r'C:\Windows\Fonts\Arial.ttf', fn_size) fn_w, fn_h = fn.getsize(fn_str) # 获取字体宽高 ct_w, ct_h = (w - fn_w) // 2, (h - fn_h) // 2 # 字体位置设置在中心 draw = ImageDraw.Draw(water) draw.text((ct_w, ct_h), fn_str, font=fn, fill=(255, 255, 255, 100)) water = water.rotate(45) # 2.图片合并,原图被水印覆盖 show_img = Image.alpha_composite(show_img, water) img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def sharpening_file(): img_list = globalvar.get_value('img_list_global') show_img = img_list[len(img_list) - 1].convert('RGB') show_img = show_img.filter(ImageFilter.SHARPEN) img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def reverse_file(): img_list = globalvar.get_value('img_list_global') show_img = img_list[len(img_list) - 1].convert('RGB') show_img = show_img.point(lambda x: 255 - x) img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def mirror_file(val): img_list = globalvar.get_value('img_list_global') show_img = img_list[len(img_list) - 1].convert('RGB') if val == 'h': show_img = show_img.transpose(Image.FLIP_LEFT_RIGHT) else: show_img = show_img.transpose(Image.FLIP_TOP_BOTTOM) img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def withdraw_file(): img_list = globalvar.get_value('img_list_global') num = len(img_list) if num == 1: # 只有一张原图,不需要撤销 return img_list.pop() globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=3, index=(len(img_list) - 1)) processing_setting.update_history()
def merge_file(): get_path = askopenfilename() if not os.path.isfile(get_path): print('不是文件') return img_list = globalvar.get_value('img_list_global') im1 = img_list[len(img_list) - 1].convert('RGB') im2 = Image.open(get_path).convert('RGB').resize(im1.size) show_img = Image.blend(im1, im2, 0.5) # im1:"alpha im3:1-alpha透明度 img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def cards_file(): img_list = globalvar.get_value('img_list_global') show_img = img_list[len(img_list) - 1].convert('RGB') # show_img = np.array(show_img) show_img.save('temp.jpg') path = r'temp.jpg' colors = g.ccbox(msg='请选择你要传入照片的背景色', title='证件照', choices=('红色', '蓝色')) if colors == False: img = cvtBackground(path, [180, 0, 0]) else: img = cvtBackground(path, [0, 0, 180]) show_img = Image.fromarray(cv2.cvtColor(img, cv2.COLOR_BGR2RGB)) img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def Mosaic_file(): img_list = globalvar.get_value('img_list_global') show_img = img_list[len(img_list) - 1].convert('RGB') im = np.array(show_img) show_img = im.copy() p1, p2 = processing_setting.get_mouse_point() left = min(p1[0], p2[0]) top = min(p1[1], p2[1]) right = max(p1[0], p2[0]) bottom = max(p1[1], p2[1]) do_mosaic(show_img, int(p1[0]), int(p1[1]), int(abs(right - left)), int(abs(bottom - top))) show_img = Image.fromarray(show_img) img_list.append(show_img) globalvar.set_value('img_list_global', img_list) project_start.show_img_method(filePath=None, flag=1) processing_setting.update_history()
def cut_file(): processing_setting.update_history() pass
def ok_button_method(): img_list = globalvar.get_value('img_list_global') last_img = globalvar.get_value('last_img_global') img_list.append(last_img) globalvar.set_value('img_list_global', img_list) processing_setting.update_history()