10 Commits

Author SHA1 Message Date
2b82a4b74a 1.0.14 2023-12-03 19:04:37 +01:00
499b7e5f42 fix(core): update 2023-12-03 19:04:36 +01:00
6b1948d834 1.0.13 2023-12-03 18:57:45 +01:00
7b340ea783 fix(core): update 2023-12-03 18:57:44 +01:00
063905bfaa 1.0.12 2023-12-03 18:41:44 +01:00
f1ad45289a fix(core): update 2023-12-03 18:41:43 +01:00
193e174fd7 1.0.11 2023-12-03 18:10:36 +01:00
703d21c426 fix(core): update 2023-12-03 18:10:35 +01:00
2d83ebac4d 1.0.10 2023-12-03 16:35:52 +01:00
7454a52d03 fix(core): update 2023-12-03 16:35:51 +01:00
4 changed files with 23 additions and 24 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartjimp",
"version": "1.0.9",
"version": "1.0.14",
"private": false,
"description": "a tool fr working with images in TypeScript",
"main": "dist_ts/index.js",

10
pnpm-lock.yaml generated
View File

@ -20,9 +20,6 @@ dependencies:
'@push.rocks/smartrequest':
specifier: ^2.0.15
version: 2.0.21
'@types/sharp':
specifier: ^0.32.0
version: 0.32.0
sharp:
specifier: ^0.33.0
version: 0.33.0
@ -1842,13 +1839,6 @@ packages:
'@types/node': 20.10.2
dev: true
/@types/sharp@0.32.0:
resolution: {integrity: sha512-OOi3kL+FZDnPhVzsfD37J88FNeZh6gQsGcLc95NbeURRGvmSjeXiDcyWzF2o3yh/gQAUn2uhh/e+CPCa5nwAxw==}
deprecated: This is a stub types definition. sharp provides its own type definitions, so you do not need this installed.
dependencies:
sharp: 0.33.0
dev: false
/@types/shortid@0.0.29:
resolution: {integrity: sha1-gJPuBBam4r8qpjOBCRFLP7/6Dps=}
dev: true

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartjimp',
version: '1.0.9',
version: '1.0.14',
description: 'a tool fr working with images in TypeScript'
}

View File

@ -1,6 +1,7 @@
import * as plugins from './smartjimp.plugins.js';
export interface IDimensions {
export interface IAssetVariation {
format?: 'avif' | 'webp' | 'png';
width?: number;
height?: number;
}
@ -18,28 +19,36 @@ export class SmartJimp {
private getCacheKey(
sourceTypeArg: 'streamfile' | 'smartfile',
sourceIdArg: string,
wantedDimensionsArg?: IDimensions
assetVariationArg?: IAssetVariation
) {
return `${sourceTypeArg}_${sourceIdArg}_${
wantedDimensionsArg
? `${wantedDimensionsArg.width || 'auto' }x${wantedDimensionsArg.height || 'auto'}`
assetVariationArg
? `${assetVariationArg.width || 'auto' }x${assetVariationArg.height || 'auto'}`
: 'original'
}`;
}
private async computeAssetVariation(assetBuffer: Buffer, wantedDimensions?: IDimensions) {
if (!wantedDimensions) {
return assetBuffer;
public async computeAssetVariation(assetBufferArg: Buffer, assetVariationArg?: IAssetVariation) {
if (!assetVariationArg) {
return assetBufferArg;
}
let sharpImage = plugins.sharp(assetBuffer);
sharpImage = sharpImage.resize(wantedDimensions.width, wantedDimensions.height);
const result = await sharpImage.resize(wantedDimensions.width, wantedDimensions.height).avif().toBuffer();
return result;
let sharpImage = plugins.sharp(assetBufferArg);
sharpImage = sharpImage.resize(assetVariationArg.width, assetVariationArg.height);
const resultResize = sharpImage.resize(assetVariationArg.width, assetVariationArg.height);
switch (assetVariationArg.format) {
case 'avif':
sharpImage = resultResize.avif();
case 'webp':
sharpImage = resultResize.webp();
case 'png':
sharpImage = resultResize.png();
}
return sharpImage.toBuffer();
}
public async getFromSmartfile(
smartfileArg: plugins.smartfile.SmartFile,
wantedDimensionsArg?: IDimensions
wantedDimensionsArg?: IAssetVariation
) {
const cacheKey = this.getCacheKey('smartfile', await smartfileArg.getHash(), wantedDimensionsArg);
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);