How to add signature to image
Contents
[
Hide
]
How to add signature to image
Issue : How to add signature to image.
Tips : To add signature to image, it is needed to use Graphics class and function DrawImage.
Example :
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pycore as aspycore | |
from aspose.imaging import Image, Graphics, Point | |
from aspose.imaging.imageoptions import PngOptions | |
import os | |
if 'TEMPLATE_DIR' in os.environ: | |
templates_folder = os.environ['TEMPLATE_DIR'] | |
else: | |
templates_folder = r"C:\Users\USER\Downloads\templates" | |
delete_output = 'SAVE_OUTPUT' not in os.environ | |
data_dir = templates_folder | |
# Create an instance of Image and load the primary image | |
with Image.load(os.path.join(data_dir, "template.tiff")) as canvas: | |
# Create another instance of Image and load the secondary image containing the signature graphics | |
with Image.load(os.path.join(data_dir, "template.jpg")) as signature: | |
# Create an instance of Graphics class and initialize it using the object of the primary image | |
graphics = Graphics(canvas) | |
# Call the DrawImage method while passing the instance of secondary image and appropriate location. The following snippet tries to draw the secondary image at the right bottom of the primary image | |
graphics.draw_image(signature, Point(canvas.width - signature.width, canvas.height - signature.height)) | |
canvas.save(os.path.join(data_dir, "result.png"), PngOptions()) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.png")) |