How to load large tiff file when memory not enough
Contents
[
Hide
]
How to load large tiff file when there is not enough memory
Issue : Fails to load large tiff file.
Tips : To load large tiff images there can be used memory strategy optimization be specifying buffer_size_hint property for your PC.
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 * | |
from aspose.imaging.fileformats.bmp import * | |
from aspose.imaging.fileformats.tiff import * | |
from aspose.imaging.fileformats.tiff.enums import * | |
from aspose.imaging.imageoptions import * | |
from aspose.imaging.sources import * | |
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 | |
file_name = os.path.join(data_dir, "template.tiff") | |
# Setting a memory limit of 10 megabytes for target loaded image | |
obj_init = LoadOptions() | |
obj_init.buffer_size_hint = 10 | |
with Image.load(file_name, obj_init) as image: | |
image.save(os.path.join(data_dir, "output.tiff"), TiffOptions(TiffExpectedFormat.DEFAULT)) | |
obj_init2 = LoadOptions() | |
obj_init2.buffer_size_hint = 10 | |
with Image.load(file_name, obj_init2) as image: | |
image.save(os.path.join(data_dir, "output.tiff"), TiffOptions(TiffExpectedFormat.TIFF_CCIT_RLE)) | |
obj_init3 = LoadOptions() | |
obj_init3.buffer_size_hint = 10 | |
with Image.load(file_name, obj_init3) as image: | |
image.save(os.path.join(data_dir, "output.tiff"), TiffOptions(TiffExpectedFormat.TIFF_DEFLATE_RGB)) | |
obj_init4 = LoadOptions() | |
obj_init4.buffer_size_hint = 10 | |
with Image.load(file_name, obj_init4) as image: | |
image.save(os.path.join(data_dir, "output.tiff"), TiffOptions(TiffExpectedFormat.TIFF_JPEG_Y_CB_CR)) | |
obj_init5 = LoadOptions() | |
obj_init5.buffer_size_hint = 10 | |
with Image.load(file_name, obj_init5) as image: | |
image.save(os.path.join(data_dir, "output.tiff"), TiffOptions(TiffExpectedFormat.TIFF_LZW_CMYK)) | |
obj_init6 = LoadOptions() | |
obj_init6.buffer_size_hint = 10 | |
with Image.load(file_name, obj_init6) as image: | |
image.save(os.path.join(data_dir, "output.tiff"), TiffOptions(TiffExpectedFormat.TIFF_NO_COMPRESSION_RGB)) | |
if delete_output: | |
os.remove(os.path.join(data_dir, "output.tiff")) |