有没有一种方法可以使用鼠标单击选择图像中的区域,并使用Python PIL裁剪这些区域? 我该如何做到这一点?
谢谢
谢谢
import Tkinter
import Image, ImageTk, ImageDraw
image_file = "svg.png"
w = Tkinter.Tk()
img = Image.open(image_file)
width, height = img.size
ca = Tkinter.Canvas(w, width=width, height=height)
ca.pack()
photoimg = ImageTk.PhotoImage("RGB", img.size)
photoimg.paste(img)
ca.create_image(width//2,height//2, image=photoimg)
Tkinter.mainloop()
我尝试制作一个类似的工具,在Jupyter系统中运行,这样您就可以裁剪图像,然后在同一个笔记本中稍后使用裁剪结果。它被设计为适用于多个图像,让您依次裁剪每个图像。看看它是否适合您。可以通过 pip install interactivecrop
安装,但您需要查看博客文章以获取使用说明。