main.py 1.2 KB

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