Skip to content

Commit

Permalink
Merge pull request #2325 from camptocamp/fix
Browse files Browse the repository at this point in the history
Avoid error when there are no legend images
  • Loading branch information
sbrunner authored May 24, 2024
2 parents 8a7fe2d + 8e30aec commit 1cc8307
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions tilecloud_chain/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,26 +364,27 @@ def _generate_legend_images(gene: TileGeneration) -> None:
response.content,
exc_info=True,
)
width = max(i.size[0] for i in legends)
height = sum(i.size[1] for i in legends)
image = Image.new("RGBA", (width, height))
y = 0
for i in legends:
image.paste(i, (0, y))
y += i.size[1]
string_io = BytesIO()
image.save(string_io, FORMAT_BY_CONTENT_TYPE[layer["legend_mime"]])
result = string_io.getvalue()
new_hash = sha1(result).hexdigest() # nosec
if new_hash != previous_hash:
previous_hash = new_hash
_send(
result,
f"1.0.0/{layer_name}/{layer['wmts_style']}/"
f"legend{zoom}.{layer['legend_extension']}",
layer["legend_mime"],
cache,
)
if legends:
width = max(i.size[0] for i in legends)
height = sum(i.size[1] for i in legends)
image = Image.new("RGBA", (width, height))
y = 0
for i in legends:
image.paste(i, (0, y))
y += i.size[1]
string_io = BytesIO()
image.save(string_io, FORMAT_BY_CONTENT_TYPE[layer["legend_mime"]])
result = string_io.getvalue()
new_hash = sha1(result).hexdigest() # nosec
if new_hash != previous_hash:
previous_hash = new_hash
_send(
result,
f"1.0.0/{layer_name}/{layer['wmts_style']}/"
f"legend{zoom}.{layer['legend_extension']}",
layer["legend_mime"],
cache,
)


def _get_resource(resource: str) -> bytes:
Expand Down

0 comments on commit 1cc8307

Please sign in to comment.