mirror of
https://github.com/lifegpc/eh-downloader.git
synced 2026-07-08 01:31:00 +08:00
add webp thumbnail support
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { join } from "@std/path";
|
||||
import { filterFilename } from "../utils.ts";
|
||||
import type { EhFile } from "../db.ts";
|
||||
import { ThumbnailFormat } from "../config.ts";
|
||||
|
||||
export enum ThumbnailGenMethod {
|
||||
Unknown,
|
||||
@@ -26,13 +27,17 @@ export type ThumbnailConfig = {
|
||||
input?: { width: number; height: number };
|
||||
};
|
||||
|
||||
export function gen_thumbnail_config_params(cfg: ThumbnailConfig) {
|
||||
export function gen_thumbnail_config_params(
|
||||
cfg: ThumbnailConfig,
|
||||
fmt: ThumbnailFormat,
|
||||
) {
|
||||
return {
|
||||
width: cfg.width.toString(),
|
||||
height: cfg.height.toString(),
|
||||
quality: cfg.quality.toString(),
|
||||
method: cfg.method.toString(),
|
||||
align: cfg.align.toString(),
|
||||
fmt: fmt.toString(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -69,10 +74,12 @@ export function generate_filename(
|
||||
base: string,
|
||||
f: EhFile,
|
||||
cfg: ThumbnailConfig,
|
||||
fmt: ThumbnailFormat,
|
||||
) {
|
||||
let method = "";
|
||||
let balign = "";
|
||||
let align = "";
|
||||
const ext = fmt == ThumbnailFormat.JPEG ? "jpg" : "webp";
|
||||
switch (cfg.align) {
|
||||
case ThumbnailAlign.Left:
|
||||
balign = "-left";
|
||||
@@ -100,7 +107,7 @@ export function generate_filename(
|
||||
return join(
|
||||
base,
|
||||
filterFilename(
|
||||
`${f.id}-${f.token}-${cfg.width}x${cfg.height}-q${cfg.quality}${method}${align}.jpg`,
|
||||
`${f.id}-${f.token}-${cfg.width}x${cfg.height}-q${cfg.quality}${method}${align}.${ext}`,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { ThumbnailFormat } from "../config.ts";
|
||||
import { ThumbnailAlign } from "./base.ts";
|
||||
import { type ThumbnailConfig, ThumbnailGenMethod } from "./base.ts";
|
||||
|
||||
@@ -45,8 +46,10 @@ export async function fb_generate_thumbnail(
|
||||
i: string,
|
||||
o: string,
|
||||
cfg: ThumbnailConfig,
|
||||
fmt: ThumbnailFormat,
|
||||
) {
|
||||
let add = "";
|
||||
const codec = fmt == ThumbnailFormat.WEBP ? "libwebp" : "mjpeg";
|
||||
if (cfg.method == ThumbnailGenMethod.Cover) {
|
||||
const size = cfg.input ?? await fb_get_size(i);
|
||||
if (!size) return false;
|
||||
@@ -90,6 +93,8 @@ export async function fb_generate_thumbnail(
|
||||
"-n",
|
||||
"-i",
|
||||
i,
|
||||
"-c",
|
||||
codec,
|
||||
"-vf",
|
||||
add,
|
||||
"-qmin",
|
||||
|
||||
Reference in New Issue
Block a user