{"record":{"id":"3465f49ee49b9dde","repo":"withastro/astro","slug":"unsupportedimageconversion","errorCode":"UnsupportedImageConversion","errorMessage":"Converting between vector (such as SVGs) and raster (such as PNGs and JPEGs) images is not currently supported.","messagePattern":"Converting between vector \\(such as SVGs\\) and raster \\(such as PNGs and JPEGs\\) images is not currently supported\\.","errorType":"exception","errorClass":"AstroError","httpStatus":null,"severity":"error","filePath":"packages/astro/src/assets/services/service.ts","lineNumber":214,"sourceCode":"\t\t}\n\t} else {\n\t\tif (!VALID_SUPPORTED_FORMATS.includes(options.src.format as any)) {\n\t\t\tthrow new AstroError({\n\t\t\t\t...AstroErrorData.UnsupportedImageFormat,\n\t\t\t\tmessage: AstroErrorData.UnsupportedImageFormat.message(\n\t\t\t\t\toptions.src.format,\n\t\t\t\t\toptions.src.src,\n\t\t\t\t\tVALID_SUPPORTED_FORMATS,\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\n\t\tif (options.widths && options.densities) {\n\t\t\tthrow new AstroError(AstroErrorData.IncompatibleDescriptorOptions);\n\t\t}\n\n\t\tif (options.src.format !== 'svg' && options.format === 'svg') {\n\t\t\tthrow new AstroError(AstroErrorData.UnsupportedImageConversion);\n\t\t}\n\t}\n}\n\n/**\n * Basic local service using the included `_image` endpoint.\n * This service intentionally does not implement `transform`.\n *\n * Example usage:\n * ```ts\n * const service = {\n *  getURL: baseService.getURL,\n *  parseURL: baseService.parseURL,\n *  getHTMLAttributes: baseService.getHTMLAttributes,\n *  async transform(inputBuffer, transformOptions) {...}\n * }\n * ```\n *","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/withastro/astro/blob/e294953aa8aadd98d5be92e60a03037b05dbdfd4/packages/astro/src/assets/services/service.ts#L196-L232","documentation":"Astro's base image service validates transform options in `getValidationOptions` and throws UnsupportedImageConversion when you request SVG output from a non-SVG source. Astro can rasterize SVGs but cannot turn a raster image (PNG, JPEG, WebP...) into a vector SVG. The check is `options.src.format !== 'svg' && options.format === 'svg'` in packages/astro/src/assets/services/service.ts.","triggerScenarios":"Calling `getImage({ src: pngImage, format: 'svg' })`, or rendering `<Image src={jpg} format=\"svg\" />` / `<Picture formats={[\"svg\"]}>` with a raster source. Only fires when the detected source format is not 'svg' while the requested output format is 'svg'.","commonSituations":"Trying to 'convert' a photo to SVG to save bandwidth; copying a `format` prop from an SVG example onto a raster image; UI presets that pass a fixed format list including svg; passing format=\"svg\" thinking it means 'serve original'.","solutions":["Remove `format: 'svg'` from the getImage()/Image call and let Astro pick a supported raster output (webp/avif/png/jpeg), or omit format entirely","If the source really is vector, point `src` at the actual .svg file (or an `import` of it) so the detected source format is svg","If you want the original bytes untouched, use `format=\"svg\"` only for SVG sources, or reference the file directly without the Image component"],"exampleFix":"// before\n<Image src={heroPng} format=\"svg\" alt=\"Hero\" />\n\n// after\n<Image src={heroPng} format=\"webp\" alt=\"Hero\" />","handlingStrategy":"validation","validationCode":"import type { ImageInputFormat, ImageOutputFormat } from 'astro/assets';\n\nconst RASTER: ReadonlySet<string> = new Set(['png', 'jpg', 'jpeg', 'webp', 'avif', 'gif']);\n\n// run before getImage()/Image\nfunction assertConversionSupported(srcFormat: ImageInputFormat, outFormat?: ImageOutputFormat) {\n  if (outFormat === 'svg' && srcFormat !== 'svg') {\n    throw new Error(`Cannot convert ${srcFormat} to svg; pick a raster output format or drop format.`);\n  }\n}","typeGuard":"function isSupportedConversion(\n  srcFormat: string,\n  outFormat: string | undefined,\n): outFormat is 'svg' | undefined {\n  return outFormat !== 'svg' || srcFormat === 'svg';\n}","tryCatchPattern":"try {\n  const img = await getImage(options);\n} catch (err) {\n  if (err instanceof AstroError && err.code === 'UnsupportedImageConversion') {\n    // strip the svg output format and retry\n    const { format: _f, ...rest } = options;\n    return getImage(rest);\n  }\n  throw err;\n}","preventionTips":["Never request format=\"svg\" unless the source file is an SVG","Centralize allowed output formats per source type in one helper used by all image call sites"],"tags":["astro","images","svg","format-conversion","validation"],"backgroundTag":"unsupported-image-conversion","analyzedSha":"e294953aa8aadd98d5be92e60a03037b05dbdfd4","analyzedAt":"2026-08-18T18:48:03.901Z","contentChangedAt":"2026-08-18T18:48:03.901Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}