{"record":{"id":"8165b7f1081f4a3b","repo":"withastro/astro","slug":"noimagemetadata-8165b7","errorCode":"NoImageMetadata","errorMessage":"Could not process image metadata for `${src}`.","messagePattern":"Could not process image metadata for `(.+?)`\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/utils/metadata.ts","lineNumber":21,"sourceCode":"import { lookup as probe } from '../utils/vendor/image-size/lookup.js';\n\n/**\n * Extracts image metadata such as dimensions, format, and orientation from the provided image data.\n *\n * @param {Uint8Array} data - The binary data of the image.\n * @param {string} [src] - The source path or URL of the image, used for error messages. Optional.\n * @return {Promise<Omit<ImageMetadata, 'src' | 'fsPath'>>} A promise that resolves with the extracted metadata, excluding `src` and `fsPath`.\n * @throws {AstroError} Throws an error if the image metadata cannot be extracted.\n */\nexport async function imageMetadata(\n\tdata: Uint8Array,\n\tsrc?: string,\n): Promise<Omit<ImageMetadata, 'src' | 'fsPath'>> {\n\tlet result;\n\ttry {\n\t\tresult = probe(data);\n\t} catch {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.NoImageMetadata,\n\t\t\tmessage: AstroErrorData.NoImageMetadata.message(src),\n\t\t});\n\t}\n\tif (result.height == null || result.width == null || !result.type) {\n\t\tthrow new AstroError({\n\t\t\t...AstroErrorData.NoImageMetadata,\n\t\t\tmessage: AstroErrorData.NoImageMetadata.message(src),\n\t\t});\n\t}\n\n\tconst { width, height, type, orientation } = result;\n\tconst isPortrait = (orientation || 0) >= 5;\n\n\treturn {\n\t\twidth: isPortrait ? height : width,\n\t\theight: isPortrait ? width : height,\n\t\tformat: type as ImageInputFormat,","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/withastro/astro/blob/d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca/packages/astro/src/assets/utils/metadata.ts#L3-L39","documentation":"Thrown by imageMetadata() when the vendored image-size probe() throws synchronously while parsing the raw bytes of an imported image. It is an AstroError (code NoImageMetadata) telling you Astro could not read any metadata from the bytes at all. The src argument is included in the message when supplied.","triggerScenarios":"Importing or processing an image whose bytes cause the probe() lookup to throw: a zero-byte file, a truncated header, bytes that are not an image at all, or an unsupported/obscure format the probe cannot recognise. Reached via the assets metadata pipeline (vite-plugin-assets, getImage, content collections).","commonSituations":"An empty or partially-downloaded image checked into src/assets; a .png/.jpg whose magic bytes were corrupted by git-lfs/line-ending rewriting; a file mislabeled with an image extension; an HEIC/AVIF variant the vendored probe does not understand on an older Astro version.","solutions":["Verify the file is non-empty and opens in an image viewer (`file src/assets/x.png`, check byte size).","Re-export or re-download the image from its source to repair corruption.","Confirm the format is supported by the vendored image-size probe (JPEG, PNG, GIF, WebP, AVIF, TIFF, BMP, ICNS, ICO, SVG).","If you control the producer, regenerate the image and re-commit it."],"exampleFix":"// before — `empty.png` is 0 bytes\nimport hero from './hero.png';\n\n// after — replace with a valid image\nimport hero from './hero.png'; // where hero.png is a real, opens-in-editor image","handlingStrategy":"validation","validationCode":"import { readFileSync, statSync } from 'node:fs';\nfunction isPlausibleImage(path: string): boolean {\n  if (statSync(path).size === 0) return false;\n  const b = readFileSync(path);\n  // check common magic bytes\n  const png = b.length >= 8 && b[0]===0x89 && b[1]===0x50 && b[2]===0x4e && b[3]===0x47;\n  const jpg = b.length >= 3 && b[0]===0xff && b[1]===0xd8 && b[2]===0xff;\n  const webp = b.length >= 12 && b.slice(0,4).toString()==='RIFF' && b.slice(8,12).toString()==='WEBP';\n  const gif = b.length >= 6 && ['GIF87a','GIF89a'].includes(b.slice(0,6).toString());\n  return png || jpg || webp || gif;\n}","typeGuard":"function hasImageMagic(b: Uint8Array): boolean {\n  if (b.length < 4) return false;\n  return (\n    (b[0]===0x89 && b[1]===0x50 && b[2]===0x4e && b[3]===0x47) || // PNG\n    (b[0]===0xff && b[1]===0xd8 && b[2]===0xff) ||                 // JPEG\n    (b[0]===0x47 && b[1]===0x49 && b[2]===0x46) ||                 // GIF\n    (b.slice(0,4).toString()==='RIFF')                              // WebP/AVIF container\n  );\n}","tryCatchPattern":null,"preventionTips":["Treat 0-byte or unopenable assets as build failures in CI.","Use git-lfs carefully and verify line-ending settings are not corrupting binary assets.","Re-export images from source rather than copying from unknown origins."],"tags":["assets","image-metadata","corruption","validation"],"backgroundTag":null,"analyzedSha":"d081033d5fe8e8a68c4bbbad4af9d2deb9c74bca","analyzedAt":"2026-08-12T13:37:29.035Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}