mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
simplfying photoworker
This commit is contained in:
parent
74e4a8160b
commit
d606df9479
@ -3,9 +3,13 @@ import {Metadata, Sharp} from 'sharp';
|
|||||||
import {Logger} from '../../Logger';
|
import {Logger} from '../../Logger';
|
||||||
import {FfmpegCommand, FfprobeData} from 'fluent-ffmpeg';
|
import {FfmpegCommand, FfprobeData} from 'fluent-ffmpeg';
|
||||||
import {FFmpegFactory} from '../FFmpegFactory';
|
import {FFmpegFactory} from '../FFmpegFactory';
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const sharp = require('sharp');
|
||||||
|
|
||||||
|
sharp.cache(false);
|
||||||
|
|
||||||
export class PhotoWorker {
|
export class PhotoWorker {
|
||||||
private static imageRenderer: (input: RendererInput) => Promise<void> = null;
|
|
||||||
private static videoRenderer: (input: RendererInput) => Promise<void> = null;
|
private static videoRenderer: (input: RendererInput) => Promise<void> = null;
|
||||||
|
|
||||||
public static render(input: RendererInput): Promise<void> {
|
public static render(input: RendererInput): Promise<void> {
|
||||||
@ -19,10 +23,7 @@ export class PhotoWorker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static renderFromImage(input: RendererInput): Promise<void> {
|
public static renderFromImage(input: RendererInput): Promise<void> {
|
||||||
if (PhotoWorker.imageRenderer === null) {
|
return ImageRendererFactory.render(input);
|
||||||
PhotoWorker.imageRenderer = ImageRendererFactory.build();
|
|
||||||
}
|
|
||||||
return PhotoWorker.imageRenderer(input);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static renderFromVideo(input: RendererInput): Promise<void> {
|
public static renderFromVideo(input: RendererInput): Promise<void> {
|
||||||
@ -58,7 +59,6 @@ export interface RendererInput {
|
|||||||
export class VideoRendererFactory {
|
export class VideoRendererFactory {
|
||||||
public static build(): (input: RendererInput) => Promise<void> {
|
public static build(): (input: RendererInput) => Promise<void> {
|
||||||
const ffmpeg = FFmpegFactory.get();
|
const ffmpeg = FFmpegFactory.get();
|
||||||
const path = require('path');
|
|
||||||
return (input: RendererInput): Promise<void> => {
|
return (input: RendererInput): Promise<void> => {
|
||||||
return new Promise((resolve, reject): void => {
|
return new Promise((resolve, reject): void => {
|
||||||
Logger.silly('[FFmpeg] rendering thumbnail: ' + input.mediaPath);
|
Logger.silly('[FFmpeg] rendering thumbnail: ' + input.mediaPath);
|
||||||
@ -121,14 +121,8 @@ export class VideoRendererFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ImageRendererFactory {
|
export class ImageRendererFactory {
|
||||||
public static build(): (input: RendererInput) => Promise<void> {
|
|
||||||
return ImageRendererFactory.Sharp();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Sharp(): (input: RendererInput) => Promise<void> {
|
public static async render(input: RendererInput): Promise<void> {
|
||||||
const sharp = require('sharp');
|
|
||||||
sharp.cache(false);
|
|
||||||
return async (input: RendererInput): Promise<void> => {
|
|
||||||
Logger.silly(
|
Logger.silly(
|
||||||
'[SharpRenderer] rendering photo:' +
|
'[SharpRenderer] rendering photo:' +
|
||||||
input.mediaPath +
|
input.mediaPath +
|
||||||
@ -164,6 +158,6 @@ export class ImageRendererFactory {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
await image.rotate().webp({effort: 6, quality: input.quality, smartSubsample: input.smartSubsample}).toFile(input.outPath);
|
await image.rotate().webp({effort: 6, quality: input.quality, smartSubsample: input.smartSubsample}).toFile(input.outPath);
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user