How To Translate Images Using OpenPyXL?

Method

img=img.rotate(0,translate=(100,-20))

Sample Code

#Translation Transformation

from openpyxl import Workbook
from openpyxl.drawing.image import Image as xlImage
from PIL import Image as pilImage

#Create a workbook
wb=Workbook()
#Get the active worksheet
ws=wb.active

# Open the original image file
img=pilImage.open('pic.jpg')

#Apply a translation transformation to the image
img=img.rotate(0,translate=(100,-20))

# Save the transformed image as a temporary file
path='image1.jpg'
img.save(path)

# Add the image to the worksheet
img=xlImage(path)
ws.add_image(img, 'A1')

# Save the workbook
wb.save('image03.xlsx')

# Delete the temporary file
import os
os.remove(path)
Translate Images Using OpenPyXL

Leave a Reply

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