Skip to content

Add filter() Function #6772

@ShiningYangYXN

Description

@ShiningYangYXN

Description

I propose adding a filter() function to apply CSS-style visual filters to arbitrary Typst content. This would allow users to dynamically modify content appearance without external tools.

Expected API:

// Function signature
#filter(
  ..args    // Filter effects with CSS-compatible values
  content: content,     // Content to apply filters to
) -> content

Example syntax:

// Filters for images
#filter(blur: 2pt, brightness: 80%)[#image("foo.png")]

// Filters for texts
#filter(drop-shadow: (x-offset: 2pt, y-offset: 2pt, blur: 1pt, paint: red)[#strong[Warning]]

// Filters for anything
#filter(saturate: 150%, hue-rotate: 45deg)[#foo-bar-baz()]

Key Parameters (partial implementation):

Filter Value Type Example
blur length 3pt
brightness ratio 120%
contrast ratio 75%
drop-shadow dictionary(x-offset: length, y-offset: length,blur: length, paint: color) (x-offset: 2pt, y-offset: 1pt, blur: 4pt, paint: rgba(0,0,0,0.5))
grayscale ratio 100%
hue-rotate angle 90deg
invert ratio 100%
opacity ratio 40%
saturate ratio 50%
sepia ratio 80%

Use Case

This feature would enable:

  1. Professional document styling (e.g., muted background images via opacity)
  2. Dynamic diagram highlighting (e.g., grayscale for inactive elements)
  3. Accessibility adjustments (e.g., contrast enhancement)
  4. Creative typography effects (text with drop-shadow/blur)

Without this, users must externally pre-process images and lack live content adjustments. Implemented natively, this would:

  • Reduce workflow friction
  • Enhance design consistency
  • Enable responsive styling based on content

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or requestvisualizeRelated to drawing and visualizations.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions