pyvips icon indicating copy to clipboard operation
pyvips copied to clipboard

dzsave_target returns NoneType not list[] as in docs

Open mgbee8 opened this issue 1 year ago • 1 comments

When i try to use image.dzsave_target it is returning a None type not a list[] as documents state

import pyvips

file_name = "./images/sample.svs"
# Load the SVS image
image = pyvips.Image.new_from_file(file_name, access="sequential")

# Tile the image
tile_size = 256  # Adjust tile size as needed
target = pyvips.Target.new_to_memory()
try:
    tiles = image.dzsave_target(target, basename="output", tile_size=tile_size, overlap=0, depth=pyvips.enums.ForeignDzDepth.ONE)
    print(type(tiles))
except pyvips.error.Error as e:
    print(e.message)
    print(e.detail)

type of tiles is NoneType not list[] as doc states

How can I get a list of the tiled images to iterate over?

mgbee8 avatar Feb 07 '24 21:02 mgbee8

Hi @mgbee8,

dzsave writes the tiles to the memory target as a zip file, so you'll need to use some other python lib to parse the zip and extract the JPEGs.

Alternatively, you can just loop over the image and crop out tiles yourself. Perhaps:

image = pyvips.Image.new_from_file(file_name, access="sequential")
tiles = [image.crop(x, y, 512, 512)
         for y in range(0, image.height, 512)
         for x in range(0, image.width, 512)]

jcupitt avatar Feb 09 '24 09:02 jcupitt