UI & Feature update - Alpha #9
@@ -17,6 +17,7 @@ export interface IMediaService {
|
|||||||
processImage(
|
processImage(
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
format?: "webp" | "avif",
|
format?: "webp" | "avif",
|
||||||
|
resize?: { width?: number; height?: number },
|
||||||
): Promise<MediaProcessingResult>;
|
): Promise<MediaProcessingResult>;
|
||||||
processVideo(
|
processVideo(
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
|
|||||||
@@ -83,8 +83,9 @@ export class MediaService implements IMediaService {
|
|||||||
async processImage(
|
async processImage(
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
format: "webp" | "avif" = "webp",
|
format: "webp" | "avif" = "webp",
|
||||||
|
resize?: { width?: number; height?: number },
|
||||||
): Promise<MediaProcessingResult> {
|
): Promise<MediaProcessingResult> {
|
||||||
return this.imageProcessor.process(buffer, { format });
|
return this.imageProcessor.process(buffer, { format, resize });
|
||||||
}
|
}
|
||||||
|
|
||||||
async processVideo(
|
async processVideo(
|
||||||
|
|||||||
@@ -13,11 +13,22 @@ export class ImageProcessorStrategy implements IMediaProcessorStrategy {
|
|||||||
|
|
||||||
async process(
|
async process(
|
||||||
buffer: Buffer,
|
buffer: Buffer,
|
||||||
options: { format: "webp" | "avif" } = { format: "webp" },
|
options: {
|
||||||
|
format: "webp" | "avif";
|
||||||
|
resize?: { width?: number; height?: number };
|
||||||
|
} = { format: "webp" },
|
||||||
): Promise<MediaProcessingResult> {
|
): Promise<MediaProcessingResult> {
|
||||||
try {
|
try {
|
||||||
const { format } = options;
|
const { format, resize } = options;
|
||||||
let pipeline = sharp(buffer);
|
let pipeline = sharp(buffer);
|
||||||
|
|
||||||
|
if (resize) {
|
||||||
|
pipeline = pipeline.resize(resize.width, resize.height, {
|
||||||
|
fit: "cover",
|
||||||
|
position: "center",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const metadata = await pipeline.metadata();
|
const metadata = await pipeline.metadata();
|
||||||
|
|
||||||
if (format === "webp") {
|
if (format === "webp") {
|
||||||
|
|||||||
Reference in New Issue
Block a user