diff --git a/demo-api/collections/mycol.yml b/demo-api/collections/mycol.yml index 7aaa9e0..13a5d48 100644 --- a/demo-api/collections/mycol.yml +++ b/demo-api/collections/mycol.yml @@ -128,3 +128,25 @@ fields: maxItems: 3 maxFileSize: "5MB" accept: ["application/pdf"] + +imageFilter: + shadow: + - width: 800 + outputType: png + removeBackground: + color: "#FFFFFF" + tolerance: 8 + fromEdges: true + edgeBlur: 1.5 + referenceWidth: 1000 + dropShadow: + color: "#000000" + opacity: 0.25 + blur: 15 + offsetX: 8 + offsetY: 8 + padding: 20 + referenceWidth: 1000 + canvas: expand + background: transparent + flatten: "#FFFFFF" diff --git a/examples/server/asset-image-processing.yml b/examples/server/asset-image-processing.yml new file mode 100644 index 0000000..064fa61 --- /dev/null +++ b/examples/server/asset-image-processing.yml @@ -0,0 +1,36 @@ +# Beispiel für einen Asset-Eintrag mit Bildverarbeitung (imageProcessing) +# (tibi-server, ProjectConfig.assets[]) — validiert gegen schemas/config/asset.schema.json. +# Hinweis: cachePath muss ein existierendes Verzeichnis ausserhalb des Quellpfads +# sein; die Ajv-Validierung prueft nur Form und Wertebereiche, keine Dateisystempfade. +name: product-images +path: ./media/products +imageProcessing: + access: public + cachePath: ./media-cache/products + allowOriginal: false + defaultFilter: shadow + allowedInputTypes: ["image/jpeg", "image/png", "image/webp"] + limits: + maxInputBytes: 26214400 + maxPixels: 20000000 + imageFilter: + shadow: + - width: 800 + outputType: png + removeBackground: + color: "#FFFFFF" + tolerance: 8 + fromEdges: true + edgeBlur: 1.5 + referenceWidth: 1000 + dropShadow: + color: "#000000" + opacity: 0.25 + blur: 15 + offsetX: 8 + offsetY: 8 + padding: 20 + referenceWidth: 1000 + canvas: expand + background: transparent + flatten: "#FFFFFF" diff --git a/index.d.ts b/index.d.ts index 479cd2d..cb9a00d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -343,6 +343,26 @@ declare global { export type PreviewConfig = string | EvalHtmlConfig | PreviewSlots /** Image filter parameters — used in both CollectionConfig.imageFilter and ImagePackage.filter() */ + export interface RemoveBackgroundParams { + color?: string + tolerance?: number + fromEdges?: boolean + edgeBlur?: number + referenceWidth?: number + } + + export interface DropShadowParams { + color?: string + opacity?: number + blur?: number + offsetX?: number + offsetY?: number + padding?: number + referenceWidth?: number + canvas?: "expand" | "fixed" + background?: string + } + export interface ImageFilterParams { width?: number height?: number @@ -355,7 +375,7 @@ declare global { | "catmullRom" | "lanczos" | "box" - | "mitchellNetravili" + | "mitchellNetravali" | "bSpline" | "gaussian" | "bartlett" @@ -387,6 +407,33 @@ declare global { skipLargerDimension?: boolean skipLargerFilesize?: boolean outputType?: "jpg" | "jpeg" | "png" | "webp" + removeBackground?: RemoveBackgroundParams + dropShadow?: DropShadowParams + flatten?: string + } + + /** Limits for asset image processing (`imageProcessing.limits`) */ + export interface AssetImageLimitsConfig { + maxInputBytes?: number + maxPixels?: number + } + + /** Asset image processing block (`imageProcessing`) */ + export interface AssetImageProcessingConfig { + access: "public" + cachePath: string + allowOriginal?: boolean + defaultFilter?: string + allowedInputTypes?: Array<"image/jpeg" | "image/png" | "image/webp"> + limits?: AssetImageLimitsConfig + imageFilter: { [name: string]: ImageFilterParams[] } | string + } + + /** Asset config entry */ + export interface AssetConfig { + name: string + path: string + imageProcessing?: AssetImageProcessingConfig } /** Collection config as returned by context.collection() – JSON-serialized from Go CollectionConfig */ @@ -573,7 +620,7 @@ declare global { lastReload: string namespace: string meta?: { [key: string]: any } - assets?: { name: string; path: string }[] + assets?: AssetConfig[] collections?: CollectionInfo[] actions?: ActionInfo[] jobs?: JobConfig[] diff --git a/schemas/config/asset.schema.json b/schemas/config/asset.schema.json index ce3f131..4a6dba7 100644 --- a/schemas/config/asset.schema.json +++ b/schemas/config/asset.schema.json @@ -13,6 +13,69 @@ }, "path": { "type": "string" + }, + "imageProcessing": { + "type": "object", + "additionalProperties": false, + "properties": { + "access": { + "type": "string", + "enum": [ + "public" + ] + }, + "cachePath": { + "type": "string" + }, + "allowOriginal": { + "type": "boolean" + }, + "defaultFilter": { + "type": "string" + }, + "allowedInputTypes": { + "type": "array", + "items": { + "type": "string", + "enum": [ + "image/jpeg", + "image/png", + "image/webp" + ] + } + }, + "limits": { + "type": "object", + "additionalProperties": false, + "properties": { + "maxInputBytes": { + "type": "integer", + "minimum": 1, + "maximum": 67108864 + }, + "maxPixels": { + "type": "integer", + "minimum": 1, + "maximum": 40000000 + } + } + }, + "imageFilter": { + "oneOf": [ + { + "type": "string" + }, + { + "$ref": "image-filter.schema.json" + } + ] + } + }, + "required": [ + "access", + "cachePath", + "imageFilter" + ] } }, "required": [ diff --git a/schemas/config/image-filter.schema.json b/schemas/config/image-filter.schema.json index 7d002f1..6561b32 100644 --- a/schemas/config/image-filter.schema.json +++ b/schemas/config/image-filter.schema.json @@ -33,7 +33,7 @@ "catmullRom", "lanczos", "box", - "mitchellNetravili", + "mitchellNetravali", "bSpline", "gaussian", "bartlett", @@ -102,6 +102,96 @@ "png", "webp" ] + }, + "removeBackground": { + "type": "object", + "additionalProperties": false, + "properties": { + "color": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + "tolerance": { + "type": "integer", + "minimum": 0, + "maximum": 255 + }, + "fromEdges": { + "type": "boolean" + }, + "edgeBlur": { + "type": "number", + "minimum": 0, + "maximum": 1000 + }, + "referenceWidth": { + "type": "integer", + "minimum": 0, + "maximum": 100000 + } + } + }, + "dropShadow": { + "type": "object", + "additionalProperties": false, + "properties": { + "color": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + "opacity": { + "type": "number", + "minimum": 0, + "maximum": 1 + }, + "blur": { + "type": "number", + "minimum": 0, + "maximum": 1000 + }, + "offsetX": { + "type": "number", + "minimum": -1000, + "maximum": 1000 + }, + "offsetY": { + "type": "number", + "minimum": -1000, + "maximum": 1000 + }, + "padding": { + "type": "number", + "minimum": 0, + "maximum": 10000 + }, + "referenceWidth": { + "type": "integer", + "minimum": 0, + "maximum": 100000 + }, + "canvas": { + "type": "string", + "enum": [ + "expand", + "fixed" + ] + }, + "background": { + "oneOf": [ + { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" + }, + { + "const": "transparent" + } + ] + } + } + }, + "flatten": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$" } } } diff --git a/scripts/validate-schemas.mjs b/scripts/validate-schemas.mjs index 3019c90..942d267 100644 --- a/scripts/validate-schemas.mjs +++ b/scripts/validate-schemas.mjs @@ -66,7 +66,8 @@ const validations = [ { schema: "asset.schema.json", pattern: "demo-api/assets/*.y*ml" }, // Server-level Abschnitt (config.yml des tibi-servers), Beispiel getrennt // vom Projekt-Demo unter examples/server/: - { schema: "embedding.schema.json", pattern: "examples/server/*.y*ml" }, + { schema: "embedding.schema.json", pattern: "examples/server/embedding*.y*ml" }, + { schema: "asset.schema.json", pattern: "examples/server/asset-*.y*ml" }, ] let hasErrors = false