Thursday, December 3, 2020

Rotate image using PIL



from tkinter import *

from PIL import ImageTk, Image


win = Tk()

win.title("Rotate Image")

win.geometry("300x300")


I = IntVar()

  

def Save(e):

  degree = I.get()

  openImage = Image.open("..\\Images\\Python.png")

  rotatedImage = openImage.rotate(degree)

  rotatedImage.save('..\\Images\\PythonRotated.png')

  pic1 = PhotoImage(file="..\\Images\\PythonRotated.png")

  lbl.config(image=pic1)

  lbl.image = pic1


scl1 = Scale(win, variable=I, from_=0, to=360, orient=HORIZONTAL)

scl1.bind("<ButtonRelease-1>", Save)

scl1.place(x=30, y=10)


openImage = Image.open("..\\Images\\Python.png")

img = ImageTk.PhotoImage(openImage)

lbl = Label(win, image=img)

lbl.place(x=30, y=60)


win.mainloop()


No comments:

Post a Comment