How To Implement Geometric Transformation of Images Using xlwings?

Method

Using the methods provided by the `Shape` object, you can perform translation, rotation, scaling, and reflection transformations on a given graphic. The implementation of these methods is exactly the same for images.

 

shp=sht.api.Shapes.AddPicture(r”D:\picpy.jpg”, True, True, 100, 50, 100, 100)

shp.IncrementRotation(30)    #Rotate 30° clockwise around the center

shp.Flip(0)    #Horizontal flip

Sample Code

#Picture Geometric Transformations

import xlwings as xw    #Import xlwings package

app=xw.App()
bk=app.books.active   #Get the active workbook
sht=bk.sheets.active    #Get the active worksheet

shp=sht.api.Shapes.AddPicture(r"D:\picpy.jpg", True, True, 100, 50, 100, 100)
shp.IncrementRotation(30)    #Rotate 30° clockwise around the center
shp.Flip(0)    #Horizontal flip

#bk.save()
#bk.close()
#app.kill()
Implement Geometric Transformation of Images Using xlwings
March 2, 2026 (0)


Leave a Reply

Your email address will not be published. Required fields are marked *