Pixelate SVG Filter
Pixelate SVG Filter is a React and Tailwind CSS component from Fancy Components, licensed MIT. Copy it and paste it into your project.
Fancy Components
MIT
other
What it is
Pixelate SVG Filter is a React and Tailwind CSS component from Fancy Components, licensed MIT. Copy it and paste it into your project.
How to use it
Open it in the catalogue, press copy, and paste it into your project. The prompt you copy carries the code and the rules that tell your agent to reproduce it without changing anything.
Five free copies a month. No card.
No packages beyond the project baseline
Licence
This component comes from Fancy Components and is redistributed under the MIT licence, which permits commercial use. The copyright notice travels with the code.
Pixelate SVG Filter
interface PixelateSvgFilterProps {
id: string
size?: number
crossLayers?: boolean
}
export default function PixelateSvgFilter({
id = "pixelate-filter",
size = 16,
crossLayers = false,
}: PixelateSvgFilterProps) {
return (
<svg className="absolute inset-0">
<defs>
<filter id={id} x="0" y="0" width="1" height="1">
{"First layer: Normal pixelation effect"}
<feConvolveMatrix
kernelMatrix="1 1 1
1 1 1
1 1 1"
result="AVG"
/>
<feFlood x="1" y="1" width="1" height="1" />
<feComposite
operator="arithmetic"
k1="0"
k2="1"
k3="0"
k4="0"
width={size}
height={size}
/>
<feTile result="TILE" />
<feComposite
in="AVG"
in2="TILE"
operator="in"
k1="0"
k2="1"
k3="0"
k4="0"
/>
<feMorphology operator="dilate" radius={size / 2} result={"NORMAL"} />
{crossLayers && (
<>
{"Second layer: Fallback with full-width tiling"}
<feConvolveMatrix
kernelMatrix="1 1 1
1 1 1
1 1 1"
result="AVG"
/>
<feFlood x="1" y="1" width="1" height="1" />
<feComposite
in2="SourceGraphic"
operator="arithmetic"
k1="0"
k2="1"
k3="0"
k4="0"
width={size / 2}
height={size}
/>
<feTile result="TILE" />
<feComposite
in="AVG"
in2="TILE"
operator="in"
k1="0"
k2="1"
k3="0"
k4="0"
/>
<feMorphology
operator="dilate"
radius={size / 2}
result={"FALLBACKX"}
/>
{"Third layer: Fallback with full-height tiling"}
<feConvolveMatrix
kernelMatrix="1 1 1
1 1 1
1 1 1"
result="AVG"
/>
<feFlood x="1" y="1" width="1" height="1" />
<feComposite
in2="SourceGraphic"
operator="arithmetic"
k1="0"
k2="1"
k3="0"
k4="0"
width={size}
height={size / 2}
/>
<feTile result="TILE" />
<feComposite
in="AVG"
in2="TILE"
operator="in"
k1="0"
k2="1"
k3="0"
k4="0"
/>
<feMorphology
operator="dilate"
radius={size / 2}
result={"FALLBACKY"}
/>
<feMerge>
<feMergeNode in="FALLBACKX" />
<feMergeNode in="FALLBACKY" />
<feMergeNode in="NORMAL" />
</feMerge>
</>
)}
{!crossLayers && <feMergeNode in="NORMAL" />}
</filter>
</defs>
</svg>
)
}