Essential CSS
JavaScript Roadmap
Learn JavaScript
Mastering Web Typography
Practical Astro
Understanding Async JS
Unorthodox Tailwind
API Masterclass
Build and Deploy
The Beginner Freelancer
Real World Node
Profile Billing Logout
Practical Astro
Lesson Plan
  1. Content Systems
    1. Introduction
    2. An import alias
    3. Using Markdown
    4. Markdown extended
    5. Markdown component
    6. Markdown component in frameworks
    7. Content collections made easy
    8. Basic blogs
    9. Blogs made easy
    10. Prev/Next navigation
    11. Pagination made easy
    12. Better tag pages
    13. Paginated tag pages
    14. Markdown layouts
    15. Partials
    16. JS over JSON Data
    17. Dynamic 404 pages
    18. Putting everything together
    19. Other useful systems
  2. Image Systems
    1. Introduction
    2. Images are complicated because of this
    3. Astro's Image component
    4. Astro's Picture component
    5. Improvements over Astro's Image and Picture Components
    6. Images in Markdown and MDX
    7. Images in framework components
    8. Background images
    9. Art Direction with Astro
    10. Videos without layout shifts
    11. GIF Replacements and background video
    12. SVGs and icons
    13. SVG backgrounds
    14. Adding noise to images
    15. Asset caching on GitHub Actions
    16. Putting everything together
    17. Other useful systems

Adding noise to images

1m:57s

If you want a retro feel to an image, it makes sense to add a little bit of noise — a grainy film layer — to it.

A hiker on a ridge
Original
A hiker on a ridge

Same image with a noise overlay on top

This sort of thing cannot be generated with CSS, but it can be made with SVG. Here’s the SVG used to generate the noise layer above.

<svg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg">
<filter id="noise">
<feTurbulence
type="fractalNoise"
baseFrequency="0.9"
numOctaves="2"
stitchTiles="stitch"
/>
<feColorMatrix values="1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 0.5 0" />
</filter>
<rect width="100%" height="100%" filter="url(#noise)" />
</svg>

The Noise Component

You don’t have to understand how to create this SVG, because what we are essentially looking to do is overlay noise on an image.

So I created a component called Noise, and I exposed a few knobs for you to play with.

frequency
0.9
strength
0.4
A hiker on a ridge
Original
A hiker on a ridge
With noise

Four knobs control how the noise looks:

  • frequency — baseFrequency on the turbulence filter. Low (0.01–0.1) gives you large soft blobs like clouds or smoke; high (0.5–1) gives you fine film grain. Defaults to 0.9.
  • strength — how visible the grain is. It scales the noise’s alpha, so 0–1 fades the grain in; above 1 it saturates into denser grain. Defaults to 0.1.
  • blend — the overlay’s mix-blend-mode. Defaults to overlay.
  • color — rainbow (the default) keeps the coloured static that turbulence naturally produces. Pass a preset (black, sepia, synthwave) or any hex value for a single-colour tint.

Putting it over an image

We can use the stack method we’ve used since the background image lesson to put the noise overlay on top of the image.

<div class="stack">
<Image src="..." />
<Noise ... />
</div>

Code snippets to copy-paste

---
import { Noise } from '@splendidlabz/astro'
---
<div style="position: relative">
<Image src="..." />
<Noise ... />
</div>