main.py 1.3 KB

123456789101112131415161718192021222324252627282930
  1. #!/usr/bin/env python3
  2. from nicegui import ui
  3. img_src = 'https://i.stack.imgur.com/PpIqU.png'
  4. mask_src = 'https://i.stack.imgur.com/OfwWp.png'
  5. with ui.row().classes('w-full flex items-center'):
  6. ui.image(img_src).style('width: 25%')
  7. ui.label('+').style('font-size: 18em')
  8. ui.image(mask_src).style('width: 25%')
  9. ui.label('=').style('font-size: 18em')
  10. image = ui.interactive_image(img_src).style('width: 25%')
  11. image.content = f'''
  12. <image xlink:href="{mask_src}" width="100%" height="100%" x="0" y="0" filter="url(#mask)" />
  13. <filter id="mask">
  14. <feComponentTransfer>
  15. <feFuncR type="linear" slope="40" intercept="-(0.5 * 40) + 0.5"/>
  16. <feFuncG type="linear" slope="40" intercept="-(0.5 * 40) + 0.5"/>
  17. <feFuncB type="linear" slope="40" intercept="-(0.5 * 40) + 0.5"/>
  18. <feFuncR type="linear" slope="1000"/>
  19. </feComponentTransfer>
  20. <feColorMatrix type="matrix" values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 3 -1 -1 0 0" />
  21. </filter>
  22. '''
  23. ui.markdown(
  24. 'Images where discovered through <https://stackoverflow.com/a/57579290/364388>. '
  25. 'SVG filters where used to colorize the mask. You may want to check out <https://webplatform.github.io/docs/svg/tutorials/smarter_svg_filters/>.'
  26. ).classes('mt-4')
  27. ui.run()