Reduce file size in tiff
Contents
[
Hide
]
Reduce file size in tiff
Issue : Reduce file size in tiff.
Tips : To reduce file size in tiff there can be used Jpeg compression.
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
from aspose.imaging.fileformats.tiff.enums import TiffPhotometrics, TiffCompressions, TiffExpectedFormat | |
from aspose.imaging.imageoptions import TiffOptions | |
from aspose.imaging import Image | |
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 | |
def compress_tiff(): | |
input_file = os.path.join(templates_folder, "template.tiff") | |
output_file = os.path.join(templates_folder, "compressed.tiff") | |
with Image.load(input_file) as image: | |
obj_init = TiffOptions(TiffExpectedFormat.DEFAULT) | |
obj_init.photometric = TiffPhotometrics.YCBCR | |
obj_init.compression = TiffCompressions.JPEG | |
obj_init.bits_per_sample = [8, 8, 8] | |
image.save(output_file, obj_init) | |
if delete_output: | |
os.remove(output_file) | |
# run | |
compress_tiff() |