Last active
July 29, 2025 14:05
-
-
Save darrylmorley/df3486ea26f6cbab50ed25e0abe3c6bb to your computer and use it in GitHub Desktop.
NextJs Image Loader for Lightspeed Retail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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