Skip to content

Instantly share code, notes, and snippets.

@darrylmorley
Last active July 29, 2025 14:05
Show Gist options
  • Save darrylmorley/df3486ea26f6cbab50ed25e0abe3c6bb to your computer and use it in GitHub Desktop.
Save darrylmorley/df3486ea26f6cbab50ed25e0abe3c6bb to your computer and use it in GitHub Desktop.
NextJs Image Loader for Lightspeed Retail
export default function lightspeedImageLoader({
src,
width,
quality,
baseImageURL = "https://res.cloudinary.com/lightspeed-retail/image/upload",
extension = "webp",
crop = "limit",
}) {
// Remove any existing transformation and get publicID
const publicIdMatch = src.match(/\/?([a-zA-Z0-9]+)\.(?:webp|jpg|png)$/);
const publicID = publicIdMatch
? publicIdMatch[1]
: src.replace(/^.*\//, "").replace(/\..*$/, "");
// Build settings string
const settings = [`w_${width}`];
if (quality) settings.push(`q_${quality}`);
const settingsSection = settings.join(",");
return `${baseImageURL}/${settingsSection}/${publicID}.${extension}`;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment