How to check if jpeg image is empty
Contents
[
Hide
]
How to check if jpeg image is empty
Issue : How to check if jpeg image is empty.
Tips : To properly check if jpeg image is empty custom user processor can be added, which will check it.
Example :
This file contains 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 RasterImage, Image, Rectangle | |
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 | |
def is_content_correct(image): | |
try: | |
image.load_argb_32_pixels(Rectangle(0, 0, 1, 1)) | |
except RuntimeError: | |
return False | |
return True | |
with aspycore.as_of(Image.load(os.path.join(data_dir, "template.jpg")), RasterImage) as image: | |
if not is_content_correct(image): | |
print("Image is corrupted!") | |
else: | |
print("Image is OK!") |