import { shouldBuildImages } from "@src/utils/envUtils";
import { getImage } from "astro:assets";
const buildImages = shouldBuildImages();
export const OG_IMAGE_SIZE = {
width: 1200,
height: 630,
};
export default async function getOptimizedOgImage(
imagePath: string,
allImages: Record<
string,
() => Promise<{
default: ImageMetadata;
}>
>,
) {
const isExternalImage =
imagePath.startsWith("https://") || imagePath.startsWith("http://");
if (!isExternalImage && !allImages[imagePath]) {
throw new Error(`OG image ${imagePath} not found`);
}
if (!buildImages) {
return null;
}
return await getImage({
src: isExternalImage ? imagePath : allImages[imagePath](),
format: "png",
quality: 90,
...OG_IMAGE_SIZE,
});
}
With experimental: { responsiveImages: true, },
This function generates more than one image, but I only need one. Is there a way to override this?