Skip to content

Commit

Permalink
snapshot: avoid internal api
Browse files Browse the repository at this point in the history
  • Loading branch information
koush committed Mar 31, 2024
1 parent be98083 commit 0b26f4d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
4 changes: 2 additions & 2 deletions plugins/snapshot/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion plugins/snapshot/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@scrypted/snapshot",
"version": "0.2.42",
"version": "0.2.43",
"description": "Snapshot Plugin for Scrypted",
"scripts": {
"scrypted-setup-project": "scrypted-setup-project",
Expand Down
12 changes: 4 additions & 8 deletions plugins/snapshot/src/image-reader.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sdk, { BufferConverter, Image, ImageOptions, MediaObject, MediaObjectOptions, ScryptedDeviceBase, ScryptedMimeTypes } from "@scrypted/sdk";
import type sharp from 'sharp';
import type { KernelEnum } from "sharp";

let hasLoadedSharp = false;
let sharpInstance: typeof sharp;
Expand All @@ -8,8 +9,6 @@ export function loadSharp() {
hasLoadedSharp = true;
try {
sharpInstance = require('sharp');
// not exposed by sharp but it exists.
(sharpInstance.kernel as any).linear = 'linear';
console.log('sharp loaded');
}
catch (e) {
Expand Down Expand Up @@ -60,11 +59,8 @@ export class VipsImage implements Image {
});
}
if (options?.resize) {
let kernel: string;
let kernel: keyof KernelEnum;
switch (options?.resize.filter) {
case 'bilinear':
kernel = 'linear';
break;
case 'lanczos':
kernel = 'lanczos2';
break;
Expand All @@ -75,12 +71,12 @@ export class VipsImage implements Image {
kernel = 'nearest';
break;
default:
kernel = 'linear';
kernel = 'cubic';
break
}
transformed.resize(typeof options.resize.width === 'number' ? Math.floor(options.resize.width) : undefined, typeof options.resize.height === 'number' ? Math.floor(options.resize.height) : undefined, {
fit: "cover",
kernel: kernel as any,
kernel: kernel,
});
}

Expand Down

0 comments on commit 0b26f4d

Please sign in to comment.