Wrapper of the Sharp image manipulation library for Gatsby plugins
Build a Node.js module that provides helper functions to query and retrieve responsive image data from Gatsby's GraphQL layer. This module will be used by Gatsby page components to fetch optimized images for blog posts.
The module must provide functions that:
/**
* Helper module for querying responsive image data from Gatsby
*/
// Image transformation options
interface ImageQueryOptions {
// Layout type for the image
layout: 'constrained' | 'fullWidth';
// Maximum width in pixels (for constrained layout)
width?: number;
// Image formats to generate
formats?: Array<'AUTO' | 'WEBP' | 'AVIF'>;
}
// Returned image data structure
interface ImageData {
src: string;
srcSet: string;
sizes: string;
sources: Array<{
srcSet: string;
sizes: string;
type: string;
}>;
width: number;
height: number;
}
/**
* Query image data from Gatsby's GraphQL layer
* @param graphql - Gatsby's GraphQL query function
* @param relativePath - Path to image file relative to source directory
* @param options - Transformation options
* @returns Image data object or null if not found
*/
export async function queryImageData(
graphql: Function,
relativePath: string,
options: ImageQueryOptions
): Promise<ImageData | null>;@generates
Provides image processing and transformation capabilities for Gatsby. Should be used for all image optimization operations including format conversion, resizing, and responsive image generation.
@satisfied-by
tessl i tessl/npm-gatsby-plugin-sharp@5.15.0docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10