diff --git a/.changeset/chatty-ants-shop.md b/.changeset/chatty-ants-shop.md
new file mode 100644
index 000000000000..4c27d993c6dd
--- /dev/null
+++ b/.changeset/chatty-ants-shop.md
@@ -0,0 +1,5 @@
+---
+'@astrojs/image': patch
+---
+
+When using remote images in SSG builds, query parameters from the original image source should be stripped from final build output
diff --git a/packages/integrations/image/src/utils/paths.ts b/packages/integrations/image/src/utils/paths.ts
index 6258d392da27..8521ac41fe9b 100644
--- a/packages/integrations/image/src/utils/paths.ts
+++ b/packages/integrations/image/src/utils/paths.ts
@@ -5,13 +5,31 @@ import type { TransformOptions } from '../loaders/index.js';
import { isRemoteImage } from './images.js';
import { shorthash } from './shorthash.js';
+function removeQueryString(src: string) {
+ const index = src.lastIndexOf('?');
+ return index > 0 ? src.substring(0, index) : src;
+}
+
+function removeExtname(src: string) {
+ const ext = path.extname(src);
+
+ if (!ext) {
+ return src;
+ }
+
+ const index = src.lastIndexOf(ext);
+ return src.substring(0, index);
+}
+
export function ensureDir(dir: string) {
fs.mkdirSync(dir, { recursive: true });
}
export function propsToFilename({ src, width, height, format }: TransformOptions) {
- const ext = path.extname(src);
- let filename = src.replace(ext, '');
+ // strip off the querystring first, then remove the file extension
+ let filename = removeQueryString(src);
+ const ext = path.extname(filename);
+ filename = removeExtname(filename);
// for remote images, add a hash of the full URL to dedupe images with the same filename
if (isRemoteImage(src)) {
diff --git a/packages/integrations/image/test/fixtures/basic-image/src/pages/index.astro b/packages/integrations/image/test/fixtures/basic-image/src/pages/index.astro
index 57b7fd97c9fc..f83897ddf59f 100644
--- a/packages/integrations/image/test/fixtures/basic-image/src/pages/index.astro
+++ b/packages/integrations/image/test/fixtures/basic-image/src/pages/index.astro
@@ -12,6 +12,8 @@ import { Image } from '@astrojs/image/components';
-
+
+
+