Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

fix: scale down oversized images on mobile when exceeding `MAX_TEXTURE_SIZE` to prevent texImage2D `INVALID_VALUE`

ksmlcf258e027e728
diff --git a/i18n/locales/en.json b/i18n/locales/en.json
index c6eebbe9..93b14fb2 100644
--- a/i18n/locales/en.json
+++ b/i18n/locales/en.json
@@ -336,6 +336,7 @@
"srgb": "sRGB",
"adobeRgb": "Adobe RGB",
"wideGamutRgb": "Wide Gamut RGB",
+ "displayP3": "Display P3",
"iccProfile": "ICC Profile",
"uncalibrated": "Uncalibrated",
"rgb": "RGB"
diff --git a/i18n/locales/ja.json b/i18n/locales/ja.json
index dcb25128..c5387db1 100644
--- a/i18n/locales/ja.json
+++ b/i18n/locales/ja.json
@@ -335,6 +335,7 @@
"srgb": "sRGB",
"adobeRgb": "Adobe RGB",
"wideGamutRgb": "ワイドガマット RGB",
+ "displayP3": "Display P3",
"iccProfile": "ICC プロファイル",
"uncalibrated": "未調整",
"rgb": "RGB"
diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.json
index 5d13e57e..717a97c4 100644
--- a/i18n/locales/zh-Hans.json
+++ b/i18n/locales/zh-Hans.json
@@ -333,6 +333,7 @@
"srgb": "sRGB",
"adobeRgb": "Adobe RGB",
"wideGamutRgb": "广色域 RGB",
+ "displayP3": "Display P3",
"iccProfile": "ICC 配置文件",
"uncalibrated": "未校准",
"rgb": "RGB"
diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.json
index 62a770a9..cb2997a6 100644
--- a/i18n/locales/zh-Hant-HK.json
+++ b/i18n/locales/zh-Hant-HK.json
@@ -332,6 +332,7 @@
"srgb": "sRGB",
"adobeRgb": "Adobe RGB",
"wideGamutRgb": "廣色域 RGB",
+ "displayP3": "Display P3",
"iccProfile": "ICC 設定檔",
"uncalibrated": "未校正",
"rgb": "RGB"
diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.json
index ad2526f6..8255a8ad 100644
--- a/i18n/locales/zh-Hant-TW.json
+++ b/i18n/locales/zh-Hant-TW.json
@@ -332,6 +332,7 @@
"srgb": "sRGB",
"adobeRgb": "Adobe RGB",
"wideGamutRgb": "廣色域 RGB",
+ "displayP3": "Display P3",
"iccProfile": "ICC 設定檔",
"uncalibrated": "未校正",
"rgb": "RGB"
diff --git a/packages/webgl-image/src/core/WebGLImageViewerEngine.ts b/packages/webgl-image/src/core/WebGLImageViewerEngine.ts
index 36c03641..0356050d 100644
--- a/packages/webgl-image/src/core/WebGLImageViewerEngine.ts
+++ b/packages/webgl-image/src/core/WebGLImageViewerEngine.ts
@@ -348,6 +348,49 @@ export class WebGLImageViewerEngine {
gl.deleteTexture(this.texture)
}
+ // 获取最大纹理尺寸并判断是否需要缩放
+ const maxTextureSize = getMaxTextureSize(gl)
+ const srcWidth =
+ (imageSource as HTMLCanvasElement).width ??
+ (imageSource as HTMLImageElement).width ??
+ (imageSource as ImageBitmap).width
+ const srcHeight =
+ (imageSource as HTMLCanvasElement).height ??
+ (imageSource as HTMLImageElement).height ??
+ (imageSource as ImageBitmap).height
+
+ let finalSource: HTMLCanvasElement | HTMLImageElement | ImageBitmap =
+ imageSource
+
+ // 如果超出最大纹理尺寸,使用离屏 canvas 等比缩放
+ if (
+ typeof srcWidth === 'number' &&
+ typeof srcHeight === 'number' &&
+ (srcWidth > maxTextureSize || srcHeight > maxTextureSize)
+ ) {
+ const scale = Math.min(
+ maxTextureSize / srcWidth,
+ maxTextureSize / srcHeight,
+ )
+
+ const targetWidth = Math.max(1, Math.floor(srcWidth * scale))
+ const targetHeight = Math.max(1, Math.floor(srcHeight * scale))
+
+ const offscreen = document.createElement('canvas')
+ offscreen.width = targetWidth
+ offscreen.height = targetHeight
+ const ctx = offscreen.getContext('2d')
+ if (ctx) {
+ ctx.imageSmoothingEnabled = true
+
+ ctx.imageSmoothingQuality = 'high'
+ ctx.drawImage(imageSource as any, 0, 0, targetWidth, targetHeight)
+ finalSource = offscreen
+ } else {
+ finalSource = imageSource
+ }
+ }
+
this.texture = gl.createTexture()
gl.bindTexture(gl.TEXTURE_2D, this.texture)
@@ -357,16 +400,20 @@ export class WebGLImageViewerEngine {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
- // 上传图像数据
+ // 上传图像数据(使用可能缩放后的来源)
gl.texImage2D(
gl.TEXTURE_2D,
0,
gl.RGBA,
gl.RGBA,
gl.UNSIGNED_BYTE,
- imageSource,
+ finalSource,
)
+ // 更新内部 image 引用为最终用于渲染的尺寸
+ this.image = finalSource as any
+ this.updatePositionBuffer()
+
return this.texture
}