From 274753002136d0c9727a35a5e89379584dfa347b Mon Sep 17 00:00:00 2001 From: David Manthey Date: Mon, 18 Apr 2022 16:11:30 -0400 Subject: [PATCH] Make it easier to write a non-tiff vips source --- CHANGELOG.md | 2 +- sources/vips/large_image_source_vips/__init__.py | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a13fdc28..f423782e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Unreleased ### Features -- Vips tile source and tiled file writer ([816](../../pull/816)) +- Vips tile source and tiled file writer ([816](../../pull/816), [827](../../pull/827), [830](../../pull/830)) ### Improvements - Handle file URLs with GDAL ([820](../../pull/820)) diff --git a/sources/vips/large_image_source_vips/__init__.py b/sources/vips/large_image_source_vips/__init__.py index 30fcd7b75..1bdd7a245 100644 --- a/sources/vips/large_image_source_vips/__init__.py +++ b/sources/vips/large_image_source_vips/__init__.py @@ -4,6 +4,7 @@ import os import threading import uuid +from pathlib import Path import cachetools import numpy @@ -445,8 +446,9 @@ def write(self, path, lossy=True, alpha=True, overwriteAllowed=True, vips_kwargs x = min(x, img.width) y = min(y, img.height) img = img.crop(x, y, w, h) - if vips_kwargs is not None: - img.write_to_file(path, **vips_kwargs) + pathIsTiff = Path(path).suffix.lower() in {'tif', 'tiff'} + if vips_kwargs is not None or not pathIsTiff: + img.write_to_file(path, **(vips_kwargs or {})) elif not lossy: img.write_to_file( path, tile_width=self.tileWidth, tile_height=self.tileHeight,