Skip to content

dzsave: Can we generate map tiles with transparent background? #245

Open
@acycliq

Description

@acycliq

I create an image with transparent background and I want to do a pyramid of tiles out of this image. I do not know how to make the tiles transparent please. Is this possible?

In the code below I sample from the bivariate normal and save the scatter plot as a transparent png file. What I want to achieve is to keep this transparency when I generate the tiles. However I got a white background and black whenever padding is needed for the tile to be square, see attached
0

I understand that the black background is because I am setting to 0 but I cannot figure out how to set for a transparent background when padding is needed. It takes a vector of 1 or 5 elements

import numpy as np
import pyvips
import matplotlib.pyplot as plt

mu = [0, 0]
scale = 1
cov = scale ** 2 * np.eye(2)
x, y = np.random.multivariate_normal(mu, cov, 1000).T

plt.plot(x, y, 'ob')
plt.savefig(r'./demo.png', transparent=True)

zoom_levels = 4
dim = 256 * 2 ** zoom_levels
im = pyvips.Image.new_from_file('demo.png', access='sequential')
im = im.colourspace('srgb')
im = im.addalpha()
factor = dim / max(im.width, im.height)
im = im.resize(factor)
im.dzsave(r'./transparent_tiles', layout='google', suffix='.jpg', background=0, skip_blanks=0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions