Manipulating EMF Files
Crop EMF Image
Image cropping usually refers to the removal of the outer parts of an image to help improve the framing. Cropping may also be used for to cut out some portion of an image to increase the focus on a particular area. The EmfImage class provides crop method that accepts an instance of the Rectangle class. You can cut out any portion of an image by providing the desired boundaries to the Rectangle object.
The code snippet below demonstrates how to crop any image by Rectangle.
import aspose.pycore as aspycore | |
from aspose.imaging import Image, Rectangle | |
from aspose.imaging.fileformats.emf import EmfImage | |
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 | |
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.emf")), EmfImage) as image: | |
image.crop(Rectangle(0, 0, 30, 30)) | |
print(image.width, "x", image.height) | |
image.save(os.path.join(data_dir, "result.emf")) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "result.emf")) |