Skip to content

Commit 613ed00

Browse files
Allow PNG custom background uploads
1 parent c8d4e86 commit 613ed00

11 files changed

Lines changed: 51 additions & 12 deletions

File tree

src/components/video-editor/SettingsPanel.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import { getTestId } from "@/utils/getTestId";
4343
import ColorPicker from "../ui/color-picker";
4444
import { AnnotationSettingsPanel } from "./AnnotationSettingsPanel";
4545
import { BlurSettingsPanel } from "./BlurSettingsPanel";
46+
import { BACKGROUND_IMAGE_ACCEPT, isSupportedBackgroundImageType } from "./backgroundImageUpload";
4647
import { CropControl } from "./CropControl";
4748
import { KeyboardShortcutsHelp } from "./KeyboardShortcutsHelp";
4849
import type {
@@ -459,9 +460,7 @@ export function SettingsPanel({
459460

460461
const file = files[0];
461462

462-
// Validate file type - only allow JPG/JPEG
463-
const validTypes = ["image/jpeg", "image/jpg"];
464-
if (!validTypes.includes(file.type)) {
463+
if (!isSupportedBackgroundImageType(file.type, file.name)) {
465464
toast.error(t("imageUpload.invalidFileType"), {
466465
description: t("imageUpload.jpgOnly"),
467466
});
@@ -1041,7 +1040,7 @@ export function SettingsPanel({
10411040
type="file"
10421041
ref={fileInputRef}
10431042
onChange={handleImageUpload}
1044-
accept=".jpg,.jpeg,image/jpeg"
1043+
accept={BACKGROUND_IMAGE_ACCEPT}
10451044
className="hidden"
10461045
/>
10471046
<Button
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { describe, expect, it } from "vitest";
2+
import { isSupportedBackgroundImageType } from "./backgroundImageUpload";
3+
4+
describe("background image upload validation", () => {
5+
it("accepts PNG images for custom backgrounds", () => {
6+
expect(isSupportedBackgroundImageType("image/png", "生成画像1.png")).toBe(true);
7+
});
8+
9+
it("accepts PNG images by extension when the browser does not provide a MIME type", () => {
10+
expect(isSupportedBackgroundImageType("", "生成画像1.png")).toBe(true);
11+
});
12+
13+
it("keeps rejecting non-image uploads", () => {
14+
expect(isSupportedBackgroundImageType("text/plain", "notes.txt")).toBe(false);
15+
});
16+
17+
it("does not allow extension fallback for explicit unsupported MIME types", () => {
18+
expect(isSupportedBackgroundImageType("text/plain", "notes.png")).toBe(false);
19+
});
20+
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const SUPPORTED_BACKGROUND_IMAGE_TYPES = new Set(["image/jpeg", "image/jpg", "image/png"]);
2+
const SUPPORTED_BACKGROUND_IMAGE_EXTENSIONS = new Set([".jpg", ".jpeg", ".png"]);
3+
4+
export const BACKGROUND_IMAGE_ACCEPT = ".jpg,.jpeg,.png,image/jpeg,image/png";
5+
6+
export function isSupportedBackgroundImageType(type: string, fileName: string): boolean {
7+
const normalizedType = type.trim().toLowerCase();
8+
if (SUPPORTED_BACKGROUND_IMAGE_TYPES.has(normalizedType)) {
9+
return true;
10+
}
11+
12+
if (normalizedType) {
13+
return false;
14+
}
15+
16+
const lowerName = fileName.trim().toLowerCase();
17+
return [...SUPPORTED_BACKGROUND_IMAGE_EXTENSIONS].some((extension) =>
18+
lowerName.endsWith(extension),
19+
);
20+
}

src/i18n/locales/en/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
},
9494
"imageUpload": {
9595
"invalidFileType": "Invalid file type",
96-
"jpgOnly": "Please upload a JPG or JPEG image file.",
96+
"jpgOnly": "Please upload a JPG, JPEG, or PNG image file.",
9797
"uploadSuccess": "Custom image uploaded successfully!",
9898
"failedToUpload": "Failed to upload image",
9999
"errorReading": "There was an error reading the file."

src/i18n/locales/es/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
},
9494
"imageUpload": {
9595
"invalidFileType": "Tipo de archivo no válido",
96-
"jpgOnly": "Por favor sube un archivo de imagen JPG o JPEG.",
96+
"jpgOnly": "Por favor sube un archivo de imagen JPG, JPEG o PNG.",
9797
"uploadSuccess": "¡Imagen personalizada subida exitosamente!",
9898
"failedToUpload": "Error al subir la imagen",
9999
"errorReading": "Hubo un error al leer el archivo."

src/i18n/locales/fr/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
},
101101
"imageUpload": {
102102
"invalidFileType": "Type de fichier invalide",
103-
"jpgOnly": "Veuillez téléverser un fichier image JPG ou JPEG.",
103+
"jpgOnly": "Veuillez téléverser un fichier image JPG, JPEG ou PNG.",
104104
"uploadSuccess": "Image personnalisée téléversée avec succès !",
105105
"failedToUpload": "Échec du téléversement de l'image",
106106
"errorReading": "Une erreur s'est produite lors de la lecture du fichier."

src/i18n/locales/ja-JP/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
},
101101
"imageUpload": {
102102
"invalidFileType": "無効なファイル形式",
103-
"jpgOnly": "JPG または JPEG 画像ファイルをアップロードしてください。",
103+
"jpgOnly": "JPG、JPEG、または PNG 画像ファイルをアップロードしてください。",
104104
"uploadSuccess": "カスタム画像が正常にアップロードされました!",
105105
"failedToUpload": "画像のアップロードに失敗しました",
106106
"errorReading": "ファイルの読み取り中にエラーが発生しました。"

src/i18n/locales/ko-KR/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
},
9494
"imageUpload": {
9595
"invalidFileType": "지원하지 않는 파일 형식입니다",
96-
"jpgOnly": "JPG 또는 JPEG 이미지 파일을 업로드해 주세요.",
96+
"jpgOnly": "JPG, JPEG 또는 PNG 이미지 파일을 업로드해 주세요.",
9797
"uploadSuccess": "커스텀 이미지가 성공적으로 업로드되었습니다!",
9898
"failedToUpload": "이미지 업로드에 실패했습니다",
9999
"errorReading": "파일을 읽는 중 오류가 발생했습니다."

src/i18n/locales/tr/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
},
9494
"imageUpload": {
9595
"invalidFileType": "Geçersiz dosya türü",
96-
"jpgOnly": "Lütfen bir JPG veya JPEG görüntü dosyası yükleyin.",
96+
"jpgOnly": "Lütfen JPG, JPEG veya PNG görüntü dosyası yükleyin.",
9797
"uploadSuccess": "Özel görüntü başarıyla yüklendi!",
9898
"failedToUpload": "Görüntü yüklenemedi",
9999
"errorReading": "Dosya okunurken bir hata oluştu."

src/i18n/locales/zh-CN/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
},
9494
"imageUpload": {
9595
"invalidFileType": "无效的文件类型",
96-
"jpgOnly": "请上传 JPG 或 JPEG 格式的图片文件。",
96+
"jpgOnly": "请上传 JPG、JPEGPNG 格式的图片文件。",
9797
"uploadSuccess": "自定义图片上传成功!",
9898
"failedToUpload": "上传图片失败",
9999
"errorReading": "读取文件时出错。"

0 commit comments

Comments
 (0)