Skip to content

Instantly share code, notes, and snippets.

@sofroniewn
Created September 7, 2019 20:17
Show Gist options
  • Save sofroniewn/62d4ec2146232abd80470f7ccefee8a0 to your computer and use it in GitHub Desktop.
Save sofroniewn/62d4ec2146232abd80470f7ccefee8a0 to your computer and use it in GitHub Desktop.
def _get_viewer_thumbnail(self):
"""Creat an overall thumbnail based on the layer thumbnails."""
thumbnail = np.zeros(layers.Layer._thumbnail_shape, dtype=np.uint8)
for layer in self.layers[::-1]:
if layer.blending == 'translucent':
f_dest = thumbnail[..., 3][..., None] / 255
f_source = 1 - layer.thumbnail[..., 3][..., None] / 255
elif layer.blending == 'additive':
f_dest = thumbnail[..., 3][..., None] / 255
f_source = 1
elif layer.blending == 'opaque':
f_dest = 0
f_source = 1
else:
raise ValueError(f'Layer blending mode not recognized, got {layer.blending}')
thumbnail = thumbnail * f_dest + layer.thumbnail * f_source
thumbnail = thumbnail.astype(np.uint8)
return thumbnail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment