#Sharp
15 messages · Page 1 of 1 (latest)
Hi @pastel cedar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Sharp is not always installed automatically.
From the docs:
- Sharp is the default image service used for
astro:assets. - With a strict package manager like pnpm, you must install
sharpmanually to use image processing. [Missing Sharp; Upgrade to v3]
Example install (if needed):
pnpm add sharp
# or
npm install sharp
If you don’t want to use Sharp at all, you can switch to a passthrough image service that does no processing:
import { defineConfig, passthroughImageService } from "astro/config";
export default defineConfig({
image: {
service: passthroughImageService(),
},
});
Regarding only JPGs in dist/astro: the provided docs don’t explain your exact output layout, so I can’t say for sure why only JPGs appear there. They only state that Sharp is the default processor and must be installed for image processing; they don’t detail which formats end up in which folders.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@pastel cedar Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@safe quarry Is there a way to find out if im missing sharp?
Let me check the knowledge base for you again. One moment! :books:
Yes. Astro has a specific error for this:
If Sharp is missing when Astro tries to use astro:assets, you’ll get an error like:
MissingSharp: Could not find Sharp. Please install Sharp (
sharp) manually into your project or migrate to another image service. [Missing Sharp]
So:
- Run a command that uses
astro:assets(e.g.astro buildwith<Image />or imported images). - If Sharp is not installed, the build should fail with the MissingSharp error above.
The docs do not describe any other built‑in way to “check” for Sharp beyond this error message.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@pastel cedar Kapa.ai is still learning and improving, please let me know how I did by reacting below.
@safe quarry My build didnt fail, so I must have sharp installed.
Why did I only get jpg images inside my dist/astro folder then?
src: desktopURL,
priority: priority,
format: "avif",
});
const desktopWebp = await getImage({
src: desktopURL,
priority: priority,
format: "webp",
});
const desktopJpg = await getImage({
src: desktopURL,
priority: priority,
format: "jpg",
});```
```<picture class:list={[className]} {...rest}>
<!-- Desktop -->
<source media="(min-width: 62.5rem)" srcset={desktopAvif.src} type="image/avif" />
<source media="(min-width: 62.5rem)" srcset={desktopWebp.src} type="image/webp" />
<source media="(min-width: 62.5rem)" srcset={desktopJpg.src} type="image/jpg" />```
Example of a part of my CustomPicture code (I didnt include the whole thing)
Let me check the knowledge base for you again. One moment! :books:
The knowledge sources you provided only document Astro’s built‑in <Picture /> component and its props (formats, fallbackFormat, pictureAttributes) and show that it will generate multiple formats (e.g. AVIF, WebP, plus a PNG/JPG fallback) when you use it. [Picture guide]
They do not describe:
- How
getImage()writes files todist/, - How many physical files are emitted per
getImage()call, or - Why only certain formats (like JPG) might appear in
dist/astro.
Because of that, I can’t reliably explain why you only see JPG files in dist/astro from the docs you’ve given.
What the docs do confirm:
- Using
<Picture />withformats={['avif', 'webp']}produces<source>tags for those formats and an<img>fallback (PNG/JPG) that is actually written as a file. [Picture guide] fallbackFormatcontrols the format of that<img>fallback (defaulting to PNG/JPG/GIF/SVG depending on the source). [Picture guide]
However, there is no explicit information in these sources about:
- Whether AVIF/WebP variants are always emitted as separate files in
dist/astro, - Or whether some formats might be inlined, cached elsewhere, or optimized away.
So, based solely on the provided docs, I can’t say why your getImage({ format: 'avif' | 'webp' | 'jpg' }) calls result in only JPG files in dist/astro. The behavior of getImage() and the exact output layout are not covered in the snippets you shared.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@pastel cedar Kapa.ai is still learning and improving, please let me know how I did by reacting below.
src: mobileImgUrl,
format: "webp",
width: 200,
height: 200,
});```
This is literally the example used in the docs, so as you can see, you can use the format property on getImage.
Why aren't I getting webp and avif images in my dist/astro folder? @safe quarry
Am I even supposed to get these images, or only jpg if that was the original file type
Let me check the knowledge base for you again. One moment! :books:
The knowledge sources you provided only document that:
- The
<Image />component (fromastro:assets) has aformatproperty, and - By default, it outputs
.webpfiles unless you specify another format. [Images format]
They do not include any details about:
- How
getImage()behaves withformat, - What files
getImage()writes intodist/astro, or - Whether Astro will emit multiple formats (e.g. AVIF, WebP, JPG) or only one, or whether it preserves the original format.
Because of this, I cannot say from the docs:
- Why you only see JPG files in
dist/astro, - Whether WebP/AVIF files should also appear there, or
- Whether Astro is expected to keep the original JPG format only.
All I can state confidently from the available docs is:
- You can specify an output image file type via a
formatproperty (documented for<Image />), and the default output is.webpwhen that property is not set. [Images format]