diff --git a/browser-runtime/scripts/test-engine.mjs b/browser-runtime/scripts/test-engine.mjs
index 54e26cb..ddee4ee 100644
--- a/browser-runtime/scripts/test-engine.mjs
+++ b/browser-runtime/scripts/test-engine.mjs
@@ -5,7 +5,27 @@ import os from 'node:os';
import path from 'node:path';
import electron from 'electron';
const directory = await mkdtemp(path.join(os.tmpdir(), 'runestone-plugin-browser-'));
+// A two-frame GIF that the server gives only one time, as some image hosts do.
+const onceGif = Buffer.from('R0lGODlhAQABAIAAAAAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQACgAAACwAAAAAAQABAAACAkQBACH5BAAKAAAALAAAAAABAAEAAAICTAEAOw==', 'base64');
+let onceGifServed = false;
+// The same GIF with 7 MB of comment blocks, so that Copy image needs more than one part.
+const comment = Buffer.concat([Buffer.from([255]), Buffer.alloc(255, 0x61)]);
+const largeGif = Buffer.concat([onceGif.subarray(0, 32), Buffer.from([0x21, 0xfe]), ...Array(28_000).fill(comment), Buffer.from([0]), onceGif.subarray(32)]);
const server = http.createServer((req, res) => {
+ if (req.url === '/direct.gif') {
+ res.writeHead(200, { 'Content-Type': 'image/gif' });
+ return res.end(largeGif);
+ }
+ if (req.url === '/large.gif') {
+ res.writeHead(200, { 'Content-Type': 'image/gif' });
+ return res.end(largeGif);
+ }
+ if (req.url === '/once.gif') {
+ if (onceGifServed) { res.writeHead(200, { 'Content-Type': 'text/html' }); return res.end('Invalid request'); }
+ onceGifServed = true;
+ res.writeHead(200, { 'Content-Type': 'image/gif' });
+ return res.end(onceGif);
+ }
if (req.url === '/picture.png') {
res.writeHead(200, { 'Content-Type': 'image/png' });
return res.end(Buffer.from('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+aD1sAAAAASUVORK5CYII=', 'base64'));
diff --git a/browser-runtime/src/engine.mjs b/browser-runtime/src/engine.mjs
index 23a68bf..5a0401d 100644
--- a/browser-runtime/src/engine.mjs
+++ b/browser-runtime/src/engine.mjs
@@ -31,6 +31,31 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
pageFocusStates.set(wc, enabled);
if (enabled) wc.focus();
}
+ // The last image that Copy image took from a page. RuneStone gets it in parts when the user pastes.
+ let copied = null;
+ const COPIED_PART = 3_000_000;
+ // The page holds the encoded image. Its bytes keep all frames of a GIF, and the website gets no second request.
+ async function loadedImage(wc, url) {
+ if (!wc.debugger.isAttached()) { wc.debugger.attach('1.3'); pageFocusStates.delete(wc); }
+ await wc.debugger.sendCommand('Page.enable');
+ try {
+ const href = value => { try { return new URL(value).href; } catch { return ''; } };
+ const nodes = [(await wc.debugger.sendCommand('Page.getResourceTree')).frameTree];
+ for (const node of nodes) {
+ // An image that opens as the page itself is the main resource of its frame.
+ const page = href(node.frame.url) === url && /^image\//.test(node.frame.mimeType) ? node.frame : undefined;
+ const resource = page ?? node.resources?.find(item => item.type === 'Image' && href(item.url) === url);
+ if (resource) {
+ const { content, base64Encoded } = await wc.debugger.sendCommand('Page.getResourceContent', { frameId: node.frame.id, url: resource.url });
+ const data = Buffer.from(content, base64Encoded ? 'base64' : 'utf8');
+ const valid = /^image\/(?:gif|png|jpeg|webp|avif|bmp)$/.test(resource.mimeType) && data.length > 0 && data.length <= 20_000_000;
+ return valid ? { mime: resource.mimeType, data } : null;
+ }
+ nodes.push(...(node.childFrames ?? []));
+ }
+ return null;
+ } finally { await wc.debugger.sendCommand('Page.disable').catch(() => {}); }
+ }
function emulateViewport(item) {
if (!item.viewport) return;
const { width, height } = item.viewport, scale = item.scale;
@@ -248,7 +273,13 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
switch (args.action) {
case 'copyLink': if (context.linkURL) clipboard.writeText(context.linkURL); break;
case 'copyImageAddress': if (context.srcURL) clipboard.writeText(context.srcURL); break;
- case 'copyImage': if (context.hasImageContents) wc.copyImageAt(Math.round(context.x * current.scale), Math.round(context.y * current.scale)); break;
+ case 'copyImage': {
+ if (!context.hasImageContents) break;
+ wc.copyImageAt(Math.round(context.x * current.scale), Math.round(context.y * current.scale));
+ const image = context.srcURL ? await loadedImage(wc, context.srcURL).catch(() => null) : null;
+ copied = image && { token: randomUUID(), tabId: current.id, url: context.srcURL, ...image };
+ return copied && { copied: { token: copied.token, url: copied.url, mime: copied.mime, size: copied.data.length } };
+ }
case 'openExternal': if (context.linkURL) await openExternal(context.linkURL); break;
case 'saveImage': case 'saveLink': {
const url = args.action === 'saveImage' ? context.srcURL : context.linkURL;
@@ -259,6 +290,14 @@ export async function createEngine({ directory, emit = () => {}, canEmitFrame =
}
return null;
}
+ case 'copiedImage': {
+ // A part stays below the line limit of the host connection.
+ if (!copied || copied.token !== args.token || copied.tabId !== args.tabId || !Number.isSafeInteger(args.offset) || args.offset < 0 || args.offset >= copied.data.length) {
+ throw new Error('The copied image is no longer available.');
+ }
+ const end = Math.min(copied.data.length, args.offset + COPIED_PART);
+ return { data: copied.data.subarray(args.offset, end).toString('base64'), next: end < copied.data.length ? end : null };
+ }
case 'input': {
const current = tab(args.tabId), wc = current.view.webContents;
const input = args.input;
diff --git a/browser-runtime/test/engine-smoke.mjs b/browser-runtime/test/engine-smoke.mjs
index 3716e9a..3c053ed 100644
--- a/browser-runtime/test/engine-smoke.mjs
+++ b/browser-runtime/test/engine-smoke.mjs
@@ -124,6 +124,56 @@ app.whenReady().then(async () => {
await assert.rejects(engine.command('contextAction', { tabId: first, token: 'expired', action: 'saveImage' }), /no longer available/);
await wc.executeJavaScript('document.querySelector("#save-image").remove();true;');
passed.push('Unicode text, native image context menus, saved image bytes and stale menu protection work');
+ // Copy image keeps the bytes that the page loaded. The test server gives this GIF only one time.
+ await wc.executeJavaScript(`document.body.insertAdjacentHTML('beforeend', '
');true;`);
+ await until(async () => await wc.executeJavaScript('document.querySelector("#copy-image").complete'));
+ const menus = events.length;
+ await engine.command('input', { tabId: first, input: { type: 'mouseDown', x: 440, y: 80, button: 'right' } });
+ await engine.command('input', { tabId: first, input: { type: 'mouseUp', x: 440, y: 80, button: 'right' } });
+ await until(() => events.slice(menus).some(event => event.event === 'context-menu' && event.hasImageContents));
+ const imageMenu = events.findLast(event => event.event === 'context-menu');
+ const { copied } = await engine.command('contextAction', { tabId: first, token: imageMenu.token, action: 'copyImage' });
+ assert.deepEqual([copied.url, copied.mime, copied.size], [`${process.env.RS_TEST_URL}once.gif`, 'image/gif', 85]);
+ const part = await engine.command('copiedImage', { tabId: first, token: copied.token, offset: 0 });
+ const bytes = Buffer.from(part.data, 'base64');
+ assert.equal(bytes.subarray(0, 6).toString(), 'GIF89a');
+ assert.equal(bytes.length, 85);
+ assert.equal(part.next, null);
+ await assert.rejects(engine.command('copiedImage', { tabId: first, token: copied.token, offset: 85 }), /no longer available/);
+ await assert.rejects(engine.command('copiedImage', { tabId: 'other', token: copied.token, offset: 0 }), /no longer available/);
+ // A large image comes in parts that stay below the line limit of the host.
+ await wc.executeJavaScript(`document.querySelector("#copy-image").src = "${process.env.RS_TEST_URL}large.gif";true;`);
+ await until(async () => await wc.executeJavaScript('document.querySelector("#copy-image").complete && document.querySelector("#copy-image").naturalWidth === 1'));
+ const largeMenus = events.length;
+ await engine.command('input', { tabId: first, input: { type: 'mouseDown', x: 440, y: 80, button: 'right' } });
+ await engine.command('input', { tabId: first, input: { type: 'mouseUp', x: 440, y: 80, button: 'right' } });
+ await until(() => events.slice(largeMenus).some(event => event.event === 'context-menu' && event.hasImageContents));
+ const large = (await engine.command('contextAction', { tabId: first, token: events.findLast(event => event.event === 'context-menu').token, action: 'copyImage' })).copied;
+ const parts = [];
+ for (let offset = 0; offset !== null;) {
+ const next = await engine.command('copiedImage', { tabId: first, token: large.token, offset });
+ assert.ok(next.data.length <= 4_000_000);
+ parts.push(Buffer.from(next.data, 'base64')); offset = next.next;
+ }
+ const whole = Buffer.concat(parts);
+ assert.ok(parts.length >= 3);
+ assert.equal(whole.length, large.size);
+ assert.equal(whole.subarray(0, 6).toString(), 'GIF89a');
+ assert.equal(whole.at(-1), 0x3b);
+ await wc.executeJavaScript('document.querySelector("#copy-image").remove();true;');
+ // An image that opens as the page itself is the main resource of the tab.
+ const direct = (await engine.command('newTab', { url: `${process.env.RS_TEST_URL}direct.gif` })).tabId;
+ const directContents = engine.tabs.get(direct).view.webContents;
+ await until(async () => await directContents.executeJavaScript('document.images[0]?.complete === true').catch(() => false));
+ const box = await directContents.executeJavaScript('(({ x, y, width, height }) => ({ x: Math.floor(x + width / 2), y: Math.floor(y + height / 2) }))(document.images[0].getBoundingClientRect())');
+ const directMenus = events.length;
+ await engine.command('input', { tabId: direct, input: { type: 'mouseDown', ...box, button: 'right' } });
+ await engine.command('input', { tabId: direct, input: { type: 'mouseUp', ...box, button: 'right' } });
+ await until(() => events.slice(directMenus).some(event => event.event === 'context-menu' && event.tabId === direct && event.hasImageContents));
+ const directCopy = (await engine.command('contextAction', { tabId: direct, token: events.findLast(event => event.event === 'context-menu').token, action: 'copyImage' })).copied;
+ assert.deepEqual([directCopy.mime, directCopy.size], ['image/gif', large.size]);
+ await engine.command('closeTab', { tabId: direct });
+ passed.push('Copy image keeps the loaded GIF bytes without a second request, also for an image that opens as the page');
await until(async () => await wc.executeJavaScript("getComputedStyle(document.querySelector('.advertisement')).display") === 'none');
assert.equal(await wc.executeJavaScript('typeof window.adExecuted'), 'undefined');
passed.push('network and cosmetic ad blocking remain active');
diff --git a/browser-runtime/test/interaction-engine.mjs b/browser-runtime/test/interaction-engine.mjs
index 43dd2f0..a7e85ce 100644
--- a/browser-runtime/test/interaction-engine.mjs
+++ b/browser-runtime/test/interaction-engine.mjs
@@ -6,7 +6,8 @@ app.setPath('userData', process.env.RS_INTERACTION_ROOT);
app.on('window-all-closed', () => {});
app.whenReady().then(async () => {
let framePending = false;
- const engine = await createEngine({ directory: process.env.RS_INTERACTION_ROOT, canEmitFrame: () => !framePending, emit: value => {
+ // The fixture server of the smoke test is on 127.0.0.1. The engine blocks local addresses for other hosts.
+ const engine = await createEngine({ directory: process.env.RS_INTERACTION_ROOT, allowedTestHosts: new Set(['127.0.0.1']), canEmitFrame: () => !framePending, emit: value => {
if (value.event === 'frame') framePending = true;
process.send?.({ event: value }, () => { if (value.event === 'frame') framePending = false; });
} });
diff --git a/docs/guides/document-tools.md b/docs/guides/document-tools.md
index aa4465f..b47e90c 100644
--- a/docs/guides/document-tools.md
+++ b/docs/guides/document-tools.md
@@ -10,6 +10,8 @@ This guide explains how to insert and edit images, read diagrams, edit Markdown
| --- | --- |
| Drag an image from the navigator into a Markdown editor | RuneStone inserts a relative link to the existing file. Press Escape to cancel the drag. |
| Drop an image from your system file manager, or paste an image | RuneStone copies the image into the workspace `attachments/` folder with a unique name, then inserts a link. |
+| Paste an image that you copied with **Copy image** in the RuneStone browser | RuneStone saves the original file that the page loaded. A GIF keeps its animation, also from a website that refuses downloads. |
+| Paste a GIF, WebP, or AVIF image that you copied in another web browser | That browser copies only the first frame. RuneStone downloads the original file from the image address, so the animation stays. If the website refuses the download, RuneStone saves the first frame and shows a message. |
Undo removes the inserted link. It keeps the image file.
diff --git a/docs/guides/project-management.md b/docs/guides/project-management.md
index e7bfa70..cb53123 100644
--- a/docs/guides/project-management.md
+++ b/docs/guides/project-management.md
@@ -116,6 +116,12 @@ To add an image to a card, paste it or drop it into the description, or select *
Use a PNG, JPEG, GIF, or WebP image of at most 50 MiB.
To show an image on the board, add **Card cover** and choose one of the images of the card.
+A web browser copies only the first frame of an image. When you paste a GIF or WebP image from a browser, RuneStone downloads the original file.
+Then the animation stays.
+
+Some websites refuse that download. Then the card gets the first frame, and RuneStone shows a message.
+To keep the animation, use **Copy image** in the RuneStone browser. That copy keeps the original file that the page loaded.
+
**More actions** → **Customize background** sets an image behind the open board, or behind All tasks.
To show the Background slideshow on the boards, see [Choose where the background shows](themes.md#choose-where-the-background-shows).
diff --git a/src-tauri/build.rs b/src-tauri/build.rs
index 7bb0651..e24c773 100644
--- a/src-tauri/build.rs
+++ b/src-tauri/build.rs
@@ -71,6 +71,8 @@ fn main() {
"workspace_delete",
"workspace_read_data_url",
"workspace_write_bytes",
+ "workspace_save_image_url",
+ "workspace_download_image",
"workspace_copy",
"workspace_abs_path",
"workspace_reveal",
diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json
index 64db564..5f29849 100644
--- a/src-tauri/capabilities/default.json
+++ b/src-tauri/capabilities/default.json
@@ -69,6 +69,8 @@
"allow-workspace-delete",
"allow-workspace-read-data-url",
"allow-workspace-write-bytes",
+ "allow-workspace-save-image-url",
+ "allow-workspace-download-image",
"allow-workspace-copy",
"allow-workspace-abs-path",
"allow-workspace-reveal",
diff --git a/src-tauri/permissions/autogenerated/workspace_download_image.toml b/src-tauri/permissions/autogenerated/workspace_download_image.toml
new file mode 100644
index 0000000..92f4b60
--- /dev/null
+++ b/src-tauri/permissions/autogenerated/workspace_download_image.toml
@@ -0,0 +1,11 @@
+# Automatically generated - DO NOT EDIT!
+
+[[permission]]
+identifier = "allow-workspace-download-image"
+description = "Enables the workspace_download_image command without any pre-configured scope."
+commands.allow = ["workspace_download_image"]
+
+[[permission]]
+identifier = "deny-workspace-download-image"
+description = "Denies the workspace_download_image command without any pre-configured scope."
+commands.deny = ["workspace_download_image"]
diff --git a/src-tauri/permissions/autogenerated/workspace_save_image_url.toml b/src-tauri/permissions/autogenerated/workspace_save_image_url.toml
new file mode 100644
index 0000000..5a4532e
--- /dev/null
+++ b/src-tauri/permissions/autogenerated/workspace_save_image_url.toml
@@ -0,0 +1,11 @@
+# Automatically generated - DO NOT EDIT!
+
+[[permission]]
+identifier = "allow-workspace-save-image-url"
+description = "Enables the workspace_save_image_url command without any pre-configured scope."
+commands.allow = ["workspace_save_image_url"]
+
+[[permission]]
+identifier = "deny-workspace-save-image-url"
+description = "Denies the workspace_save_image_url command without any pre-configured scope."
+commands.deny = ["workspace_save_image_url"]
diff --git a/src-tauri/src/browser.rs b/src-tauri/src/browser.rs
index 76036f3..274fae0 100644
--- a/src-tauri/src/browser.rs
+++ b/src-tauri/src/browser.rs
@@ -34,6 +34,7 @@ const COMMANDS: &[&str] = &[
"insertText",
"edit",
"contextAction",
+ "copiedImage",
"frameAck",
"createProfile",
"renameProfile",
@@ -480,7 +481,7 @@ impl BrowserState {
let _ = app.emit_to(&source, "browser-tab-moved", json!({ "tabId": id }));
return Ok(worker.routing.lock()?.snapshot(result, owner));
}
- if ["closeTab", "navigate", "back", "forward", "reload", "stop", "find", "stopFind", "openExternal", "moveToWindow", "resize", "visible", "focus", "input", "insertText", "edit", "contextAction", "frameAck", "bookmark", "agentSnapshot"].contains(&command) {
+ if ["closeTab", "navigate", "back", "forward", "reload", "stop", "find", "stopFind", "openExternal", "moveToWindow", "resize", "visible", "focus", "input", "insertText", "edit", "contextAction", "copiedImage", "frameAck", "bookmark", "agentSnapshot"].contains(&command) {
let id = args["tabId"].as_str().ok_or("Invalid browser tab.")?;
match worker.routing.lock()?.owners.get(id) {
Some(window) if window == owner => {},
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index bf58c7d..9c6c90b 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -107,6 +107,8 @@ pub fn run() {
workspace::workspace_delete,
workspace::workspace_read_data_url,
workspace::workspace_write_bytes,
+ workspace::workspace_save_image_url,
+ workspace::workspace_download_image,
workspace::workspace_copy,
workspace::workspace_abs_path,
workspace::workspace_reveal,
diff --git a/src-tauri/src/workspace.rs b/src-tauri/src/workspace.rs
index c0d74c7..add0c30 100644
--- a/src-tauri/src/workspace.rs
+++ b/src-tauri/src/workspace.rs
@@ -967,10 +967,14 @@ fn read_data_url(root: &Path, rel: &str) -> Result {
}
let bytes = fsutil::read_to_limit(file, MAX_IMAGE_BYTES as u64)?
.ok_or_else(|| Error::new("image is too large"))?;
- Ok(format!(
+ Ok(data_url(mime, &bytes))
+}
+
+fn data_url(mime: &str, bytes: &[u8]) -> String {
+ format!(
"data:{mime};base64,{}",
base64::Engine::encode(&base64::engine::general_purpose::STANDARD, bytes)
- ))
+ )
}
fn copy_destination(path: &Path, number: u32) -> PathBuf {
@@ -1244,6 +1248,108 @@ fn write_image(root: &Path, rel: &str, base64: &str) -> Result<()> {
fsutil::write_bytes(&path, &bytes)
}
+/// Save the original of an image that a web page copied. The clipboard has only a still copy,
+/// so an animated GIF needs its source file. `rel` has no extension. The format of the
+/// downloaded file sets it. Returns the path of the new file.
+#[tauri::command]
+pub async fn workspace_save_image_url(
+ window: tauri::Window,
+ state: State<'_, WorkspaceState>,
+ url: String,
+ rel: String,
+) -> Result {
+ let root = current_root(&state, window.label())?;
+ blocking(move || {
+ let bytes = download_image(&url)?;
+ save_image(&root, &rel, &bytes)
+ })
+ .await
+}
+
+/// Download a web image and return it as a data URL. Project Management keeps card images
+/// as data URLs, so this gives a card the original of a copied image.
+#[tauri::command]
+pub async fn workspace_download_image(url: String) -> Result {
+ blocking(move || image_data_url(&download_image(&url)?)).await
+}
+
+fn image_data_url(bytes: &[u8]) -> Result {
+ let extension = image_extension(bytes).ok_or_else(|| Error::new("file is not an image"))?;
+ let mime = mime_from_path(Path::new(&format!("image.{extension}")))
+ .ok_or_else(|| Error::new("file is not an image"))?;
+ Ok(data_url(mime, bytes))
+}
+
+fn download_image(url: &str) -> Result> {
+ use std::io::Read;
+ let web = |url: &reqwest::Url| matches!(url.scheme(), "http" | "https");
+ let url = reqwest::Url::parse(url).map_err(|_| Error::new("invalid image address"))?;
+ if !web(&url) {
+ return Err(Error::new("image address is not http or https"));
+ }
+ let client = reqwest::blocking::Client::builder()
+ .user_agent(concat!("RuneStone/", env!("CARGO_PKG_VERSION")))
+ .connect_timeout(Duration::from_secs(10))
+ .timeout(Duration::from_secs(30))
+ .redirect(reqwest::redirect::Policy::custom(move |attempt| {
+ if attempt.previous().len() >= 5 || !web(attempt.url()) {
+ attempt.stop()
+ } else {
+ attempt.follow()
+ }
+ }))
+ .build()
+ .map_err(Error::from_display)?;
+ let response = client.get(url).send().map_err(Error::from_display)?;
+ if !response.status().is_success() {
+ return Err(Error::new(format!("image server answered {}", response.status())));
+ }
+ let mut bytes = Vec::new();
+ response.take(MAX_IMAGE_BYTES as u64 + 1).read_to_end(&mut bytes)?;
+ if bytes.len() > MAX_IMAGE_BYTES {
+ return Err(Error::new("image is too large"));
+ }
+ Ok(bytes)
+}
+
+fn save_image(root: &Path, rel: &str, bytes: &[u8]) -> Result {
+ let extension = image_extension(bytes).ok_or_else(|| Error::new("file is not an image"))?;
+ let rel = format!("{rel}.{extension}");
+ let path = resolve_for_write(root, &rel)?;
+ check_new_components(root, &rel)?;
+ if path.exists() {
+ return Err(Error::new("a file with that name already exists"));
+ }
+ if let Some(parent) = path.parent() {
+ fs::create_dir_all(parent)?;
+ }
+ fsutil::write_bytes(&path, bytes)?;
+ Ok(rel)
+}
+
+/// The extension of a raster image format from its first bytes. A web server can send a
+/// wrong type, and an SVG file can contain scripts, so the type header and SVG do not count.
+fn image_extension(bytes: &[u8]) -> Option<&'static str> {
+ let at = |start: usize, value: &[u8]| bytes.get(start..start + value.len()) == Some(value);
+ if at(0, b"GIF87a") || at(0, b"GIF89a") {
+ Some("gif")
+ } else if at(0, b"\x89PNG\r\n\x1a\n") {
+ Some("png")
+ } else if at(0, b"\xff\xd8\xff") {
+ Some("jpg")
+ } else if at(0, b"RIFF") && at(8, b"WEBP") {
+ Some("webp")
+ } else if at(4, b"ftypavif") || at(4, b"ftypavis") {
+ Some("avif")
+ } else if at(0, b"BM") {
+ Some("bmp")
+ } else if at(0, b"\0\0\x01\0") {
+ Some("ico")
+ } else {
+ None
+ }
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -1598,6 +1704,50 @@ mod tests {
fs::remove_dir_all(root).unwrap();
}
+ #[test]
+ fn image_formats_come_from_the_file_contents() {
+ assert_eq!(image_extension(b"GIF89a\x01\0"), Some("gif"));
+ assert_eq!(image_extension(b"GIF87a"), Some("gif"));
+ assert_eq!(image_extension(b"\x89PNG\r\n\x1a\n\0"), Some("png"));
+ assert_eq!(image_extension(b"\xff\xd8\xff\xe0"), Some("jpg"));
+ assert_eq!(image_extension(b"RIFF\0\0\0\0WEBPVP8 "), Some("webp"));
+ assert_eq!(image_extension(b"\0\0\0\x1cftypavif"), Some("avif"));
+ assert_eq!(image_extension(b"BM\0\0"), Some("bmp"));
+ assert_eq!(image_extension(b"\0\0\x01\0\x01\0"), Some("ico"));
+ assert_eq!(image_extension(b"