libvips / pyvips

python binding for libvips using cffi
MIT License
649 stars 50 forks source link

dzsave_target returns NoneType not list[] as in docs #451

Open mgbee8 opened 9 months ago

mgbee8 commented 9 months ago

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?

jcupitt commented 9 months ago

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)]