def emboss(): global clipboard_image try: img = LAYERS_DICT['canvas'] img = img.resize((root.winfo_screenwidth(), root.winfo_screenheight())) img = img.filter(ImageFilter.EMBOSS()) canvas.image_tk = ImageTk.PhotoImage(img) image_id = LAYERS_DICT['canvas'].create_image(0, 0, anchor=NW) LAYERS_DICT['canvas'].itemconfigure(image_id, image=canvas.image_tk) LAYERS_DICT['image'] = img LAYERS_DICT['img'] = image_id except: pass try: clipboard_image = ImageGrab.grabclipboard() clipboard_image = clipboard_image.resize( (root.winfo_screenwidth(), root.winfo_screenheight())) clipboard_image = clipboard_image.filter(ImageFilter.EMBOSS()) canvas.image_tk = ImageTk.PhotoImage(clipboard_image) image_id = LAYERS_DICT['canvas'].create_image(0, 0, anchor=NW) LAYERS_DICT['canvas'].itemconfigure(image_id, image=canvas.image_tk) LAYERS_DICT['image'] = clipboard_image LAYERS_DICT['img'] = image_id except: pass if SAVED == False: root.title('Shape Editor • Unsaved') else: root.title(f'Shape Editor • {str(root.filename)} •')
def update_image(original, blur, contrast, emboss, contour, flipx, flipy): global image image = original.filter(ImageFilter.GaussianBlur(blur)) image = image.filter(ImageFilter.UnsharpMask(contrast)) if emboss: image = image.filter(ImageFilter.EMBOSS()) if contour: image = image.filter(ImageFilter.CONTOUR()) if flipx: image = ImageOps.mirror(image) if flipy: image = ImageOps.flip(image) bio = BytesIO() image.save(bio, format='PNG') window['-IMAGE-'].update(data=bio.getvalue())
def applyFilter(imgObj, outpLoc, filterType, customArgs=[0]): """Aplly filter to an image, if arguments arr required use the list customArgs Help from: https://hhsprings.bitbucket.io/docs/programming/examples/python/PIL/ImageFilter.html""" # format the output dir: if it doesnt exist create it if os.path.isdir(outpLoc): pass else: os.makedirs(outpLoc) # check if the imgObj is a thumbnail already if "filtr" in imgObj.fileName: # don't do anything return False # apply filter based on filter type: # open image file im = Image.open(imgObj.fileLOC) # apply filter based on filterType argument if filterType == "BLUR": currImFltr = im.filter(ImageFilter.BoxBlur(customArgs[0])) elif filterType == "CONTOUR": currImFltr = im.filter(ImageFilter.CONTOUR()) elif filterType == "DETAIL": currImFltr = im.filter(ImageFilter.DETAIL()) elif filterType == "EDGE_ENHANCE": currImFltr = im.filter(ImageFilter.EDGE_ENHANCE_MORE()) elif filterType == "EMBOSS": currImFltr = im.filter(ImageFilter.EMBOSS()) elif filterType == "FIND_EDGES": currImFltr = im.filter(ImageFilter.FIND_EDGES()) elif filterType == "UNSHARP_MASK": currImFltr = im.filter( ImageFilter.UnsharpMask(radius=customArgs[0], percent=customArgs[1], threshold=customArgs[2])) else: print(f"no filter for filter type: {filterType}") return False # save filtered image currImFltr.save(outpLoc + "filtr-" + filterType + "-" + imgObj.fileName)
import PIL from PIL import Image, ImageStat, ImageFilter im = Image.open('tulips.png') im1 = im.filter(ImageFilter.EMBOSS()) im1.save('tulips_emboss.png') im2 = im1.filter(ImageFilter.EMBOSS()) im2.save('ltulips_emboss_1.png')
def process_image_emboss(img_name): img = Image.open(pathlib.Path(img_name)) img = img.filter(ImageFilter.EMBOSS()) img.save(export_folder + "/Emboss_" + format(Path(img_name).stem) + image_extension) print("Emboss Filter added successfully")
def emboss(image: Image.Image) -> Image.Image: return _apply_filter(image, ImageFilter.EMBOSS())