tone
Photos in brand colors: a duotone or a halftone, with color back on hover.
Live preview needs WebGPU or WebGL 2. A photo of surf breaking over brown rocks, shown in black and white, as a duotone or as a halftone of dots.
This example failed to draw.
Usage
Put it on img, video. start() registers tone, so the attribute alone puts it on an element. The tabs below are the example above, with the values you set.
To change its code, copy the source into your effects folder; the copy replaces the built-in.
npx @dioramajs/diorama add tone<img src="/media/coast/surf-1440.avif" width="1440" height="960" data-dio="tone"/>import { start } from '@dioramajs/diorama'
const app = start()app.attach('img', 'tone', { style: 'duotone', reveal: 'none', color: '#000000', background: '#ffffff', strength: 1, contrast: 1, cell: 6, angle: 45, radius: 140, duration: 0.4,})import { start } from '@dioramajs/diorama'import tone from '@dioramajs/media/tone'
const app = start()app.attach('img', tone({ style: 'duotone', reveal: 'none', color: '#000000', background: '#ffffff', strength: 1, contrast: 1, cell: 6, angle: 45, radius: 140, duration: 0.4,}))Page transitions
Fades with the page transition; a flight carries the toned copy. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
stylerebuildsdata-dio-style | 'duotone' | 'halftone' | 'duotone' |
|
colordata-dio-color | color | '#000000' | Ink: the halftone dots. Lighter than background gives light dots on a dark ground. |
backgrounddata-dio-background | color | '#ffffff' | Paper behind the dots. In duotone the darker of color and background takes the shadows. |
strengthdata-dio-strength | number0 to 1 | 1 | 0 shows the original photo, 1 the full tone. |
contrastdata-dio-contrast | number0 to 2 | 1 | Contrast of lightness before toning. |
celldata-dio-cell | number2 to 32 px | 6 | Step of the halftone grid in CSS px. |
angledata-dio-angle | number0 to 90° | 45 | Angle of the halftone grid. |
revealrebuildsdata-dio-reveal | 'none' | 'fade' | 'spot' | 'view' | 'none' |
|
radiusdata-dio-radius | number20 to 400 px | 140 | Radius of the spot. |
durationdata-dio-duration | number0 to 2 s | 0.4 | Length of the fade to color and back. |
Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.
Inputs and frames
Draws only while something on it moves, then stops. Only while the color fades or the spot moves; none at rest. view decides in the frames the scroll draws anyway. How a frame is decided.
Reduced motion and touch
With reduced motion it shows a still frame: motion inputs are zero and time stands still. fade takes 0.15 s, and spot acts as fade.
Runs on every device. The tone stays: fade and spot need a hovering pointer. view works on touch.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { tone: { reducedMotion: 'off' } } })Cost and quality
- Download
- 2.1 KB min+gzip the first time a page uses it
- GPU
- One texture read and OKLab conversions per pixel.
- Memory
- The image only.
- Frames
- Idle at rest
It runs from the low tier up. Every tier draws it the same way. The quality plugin picks the tier for each device.
Recipes
Room cards in the brand’s colors
Photos from different shoots look like one set once they share two colors. Give every card the brand’s ink and paper, and reveal="fade" brings the real color back under the pointer, so the reader still sees what the room looks like before booking it.
-
Ocean Room from $310
-
Glass Room from $380
-
Twin with Fireplace from $260
Live preview needs WebGPU or WebGL 2. Three hotel room photos in navy and cream that turn back to color under the pointer.
This example failed to draw.
<ul class="rooms"> <li> <img src="/media/hotel/ocean-room.avif" width="800" height="600" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="fade" /> <p>Ocean Room <span>from $310</span></p> </li> <li> <img src="/media/hotel/glass-room.avif" width="800" height="600" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="fade" /> <p>Glass Room <span>from $380</span></p> </li> <li> <img src="/media/hotel/twin-room.avif" width="800" height="600" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="fade" /> <p>Twin with Fireplace <span>from $260</span></p> </li></ul>Light dots on a dark site
On a dark page, make color the light one: the dots are then light on a dark ground and grow in the highlights, like a screen print on black paper. A lineup of acts photographed by different people reads as one poster.
-
Vesper Array Friday, 21:40
-
Signal Fires Saturday, 23:10
Live preview needs WebGPU or WebGL 2. Two instrument photos as light blue halftone dots on dark navy, as on a festival lineup.
This example failed to draw.
<ul class="stages"> <li> <img src="/media/festival/cello.webp" width="960" height="1200" data-dio="tone" data-dio-style="halftone" data-dio-color="#7fd3ff" data-dio-background="#081634" /> <p><b>Vesper Array</b> Friday, 21:40</p> </li> <li> <img src="/media/festival/flugelhorn.webp" width="960" height="1200" data-dio="tone" data-dio-style="halftone" data-dio-color="#7fd3ff" data-dio-background="#081634" /> <p><b>Signal Fires</b> Saturday, 23:10</p> </li></ul>Team photos that turn to color on phones
fade and spot need a pointer that hovers, so on a phone the photos would stay toned. reveal="view" brings the color back while a photo crosses the middle half of the viewport, as the reader scrolls a team page.
<img src="/team/leo.avif" data-dio="tone" data-dio-color="#1d2a3a" data-dio-background="#f4e3c3" data-dio-reveal="view"/>The same look without WebGL
Before the engine loads, and on devices without WebGL, the photo shows in color. A CSS filter gives a close black and white for the default look; the copy draws over it once it runs.
img[data-dio~="tone"] { filter: grayscale(1);}Notes
The tone changes how a photo looks, not what it says: its alt stays the same. Do not use it on pictures that carry information in their color, such as charts, maps or the color choices of a product.
For halftone, keep cell at 4 px or more. Smaller dots fall between the pixels of a standard screen and show a moiré pattern.
style and reveal rebuild the effect; the colors, strength and the grid change live, so a theme switch can write color and background from code.