Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
6b1948d834 | |||
7b340ea783 | |||
063905bfaa | |||
f1ad45289a | |||
193e174fd7 | |||
703d21c426 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartjimp",
|
"name": "@push.rocks/smartjimp",
|
||||||
"version": "1.0.10",
|
"version": "1.0.13",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "a tool fr working with images in TypeScript",
|
"description": "a tool fr working with images in TypeScript",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
20
pnpm-lock.yaml
generated
20
pnpm-lock.yaml
generated
@ -5,6 +5,21 @@ settings:
|
|||||||
excludeLinksFromLockfile: false
|
excludeLinksFromLockfile: false
|
||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
|
'@img/sharp-darwin-arm64':
|
||||||
|
specifier: ^0.33.0
|
||||||
|
version: 0.33.0
|
||||||
|
'@img/sharp-darwin-x64':
|
||||||
|
specifier: ^0.33.0
|
||||||
|
version: 0.33.0
|
||||||
|
'@img/sharp-linux-arm64':
|
||||||
|
specifier: ^0.33.0
|
||||||
|
version: 0.33.0
|
||||||
|
'@img/sharp-linux-x64':
|
||||||
|
specifier: ^0.33.0
|
||||||
|
version: 0.33.0
|
||||||
|
'@img/sharp-win32-x64':
|
||||||
|
specifier: ^0.33.0
|
||||||
|
version: 0.33.0
|
||||||
'@push.rocks/levelcache':
|
'@push.rocks/levelcache':
|
||||||
specifier: ^3.0.3
|
specifier: ^3.0.3
|
||||||
version: 3.0.6
|
version: 3.0.6
|
||||||
@ -441,7 +456,6 @@ packages:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@img/sharp-libvips-darwin-arm64': 1.0.0
|
'@img/sharp-libvips-darwin-arm64': 1.0.0
|
||||||
dev: false
|
dev: false
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@img/sharp-darwin-x64@0.33.0:
|
/@img/sharp-darwin-x64@0.33.0:
|
||||||
resolution: {integrity: sha512-pu/nvn152F3qbPeUkr+4e9zVvEhD3jhwzF473veQfMPkOYo9aoWXSfdZH/E6F+nYC3qvFjbxbvdDbUtEbghLqw==}
|
resolution: {integrity: sha512-pu/nvn152F3qbPeUkr+4e9zVvEhD3jhwzF473veQfMPkOYo9aoWXSfdZH/E6F+nYC3qvFjbxbvdDbUtEbghLqw==}
|
||||||
@ -452,7 +466,6 @@ packages:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@img/sharp-libvips-darwin-x64': 1.0.0
|
'@img/sharp-libvips-darwin-x64': 1.0.0
|
||||||
dev: false
|
dev: false
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@img/sharp-libvips-darwin-arm64@1.0.0:
|
/@img/sharp-libvips-darwin-arm64@1.0.0:
|
||||||
resolution: {integrity: sha512-VzYd6OwnUR81sInf3alj1wiokY50DjsHz5bvfnsFpxs5tqQxESoHtJO6xyksDs3RIkyhMWq2FufXo6GNSU9BMw==}
|
resolution: {integrity: sha512-VzYd6OwnUR81sInf3alj1wiokY50DjsHz5bvfnsFpxs5tqQxESoHtJO6xyksDs3RIkyhMWq2FufXo6GNSU9BMw==}
|
||||||
@ -535,7 +548,6 @@ packages:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@img/sharp-libvips-linux-arm64': 1.0.0
|
'@img/sharp-libvips-linux-arm64': 1.0.0
|
||||||
dev: false
|
dev: false
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@img/sharp-linux-arm@0.33.0:
|
/@img/sharp-linux-arm@0.33.0:
|
||||||
resolution: {integrity: sha512-4horD3wMFd5a0ddbDY8/dXU9CaOgHjEHALAddXgafoR5oWq5s8X61PDgsSeh4Qupsdo6ycfPPSSNBrfVQnwwrg==}
|
resolution: {integrity: sha512-4horD3wMFd5a0ddbDY8/dXU9CaOgHjEHALAddXgafoR5oWq5s8X61PDgsSeh4Qupsdo6ycfPPSSNBrfVQnwwrg==}
|
||||||
@ -568,7 +580,6 @@ packages:
|
|||||||
optionalDependencies:
|
optionalDependencies:
|
||||||
'@img/sharp-libvips-linux-x64': 1.0.0
|
'@img/sharp-libvips-linux-x64': 1.0.0
|
||||||
dev: false
|
dev: false
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@img/sharp-linuxmusl-arm64@0.33.0:
|
/@img/sharp-linuxmusl-arm64@0.33.0:
|
||||||
resolution: {integrity: sha512-1QLbbN0zt+32eVrg7bb1lwtvEaZwlhEsY1OrijroMkwAqlHqFj6R33Y47s2XUv7P6Ie1PwCxK/uFnNqMnkd5kg==}
|
resolution: {integrity: sha512-1QLbbN0zt+32eVrg7bb1lwtvEaZwlhEsY1OrijroMkwAqlHqFj6R33Y47s2XUv7P6Ie1PwCxK/uFnNqMnkd5kg==}
|
||||||
@ -618,7 +629,6 @@ packages:
|
|||||||
os: [win32]
|
os: [win32]
|
||||||
requiresBuild: true
|
requiresBuild: true
|
||||||
dev: false
|
dev: false
|
||||||
optional: true
|
|
||||||
|
|
||||||
/@isaacs/cliui@8.0.2:
|
/@isaacs/cliui@8.0.2:
|
||||||
resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==}
|
resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==}
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartjimp',
|
name: '@push.rocks/smartjimp',
|
||||||
version: '1.0.10',
|
version: '1.0.13',
|
||||||
description: 'a tool fr working with images in TypeScript'
|
description: 'a tool fr working with images in TypeScript'
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import * as plugins from './smartjimp.plugins.js';
|
import * as plugins from './smartjimp.plugins.js';
|
||||||
|
|
||||||
export interface IDimensions {
|
export interface IAssetVariation {
|
||||||
|
format?: 'avif' | 'webp' | 'png';
|
||||||
width?: number;
|
width?: number;
|
||||||
height?: number;
|
height?: number;
|
||||||
}
|
}
|
||||||
@ -18,28 +19,36 @@ export class SmartJimp {
|
|||||||
private getCacheKey(
|
private getCacheKey(
|
||||||
sourceTypeArg: 'streamfile' | 'smartfile',
|
sourceTypeArg: 'streamfile' | 'smartfile',
|
||||||
sourceIdArg: string,
|
sourceIdArg: string,
|
||||||
wantedDimensionsArg?: IDimensions
|
assetVariationArg?: IAssetVariation
|
||||||
) {
|
) {
|
||||||
return `${sourceTypeArg}_${sourceIdArg}_${
|
return `${sourceTypeArg}_${sourceIdArg}_${
|
||||||
wantedDimensionsArg
|
assetVariationArg
|
||||||
? `${wantedDimensionsArg.width || 'auto' }x${wantedDimensionsArg.height || 'auto'}`
|
? `${assetVariationArg.width || 'auto' }x${assetVariationArg.height || 'auto'}`
|
||||||
: 'original'
|
: 'original'
|
||||||
}`;
|
}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async computeAssetVariation(assetBuffer: Buffer, wantedDimensions?: IDimensions) {
|
public async computeAssetVariation(assetBufferArg: Buffer, assetVariationArg?: IAssetVariation) {
|
||||||
if (!wantedDimensions) {
|
if (!assetVariationArg) {
|
||||||
return assetBuffer;
|
return assetBufferArg;
|
||||||
}
|
}
|
||||||
let sharpImage = plugins.sharp(assetBuffer);
|
let sharpImage = plugins.sharp(assetBufferArg);
|
||||||
sharpImage = sharpImage.resize(wantedDimensions.width, wantedDimensions.height);
|
sharpImage = sharpImage.resize(assetVariationArg.width, assetVariationArg.height);
|
||||||
const result = await sharpImage.resize(wantedDimensions.width, wantedDimensions.height).avif().toBuffer();
|
const resultResize = sharpImage.resize(assetVariationArg.width, assetVariationArg.height);
|
||||||
return result;
|
switch (assetVariationArg.format) {
|
||||||
|
case 'avif':
|
||||||
|
sharpImage = resultResize.avif();
|
||||||
|
case 'webp':
|
||||||
|
sharpImage = resultResize.webp();
|
||||||
|
case 'png':
|
||||||
|
sharpImage = resultResize.png();
|
||||||
|
}
|
||||||
|
return sharpImage.toBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getFromSmartfile(
|
public async getFromSmartfile(
|
||||||
smartfileArg: plugins.smartfile.SmartFile,
|
smartfileArg: plugins.smartfile.SmartFile,
|
||||||
wantedDimensionsArg?: IDimensions
|
wantedDimensionsArg?: IAssetVariation
|
||||||
) {
|
) {
|
||||||
const cacheKey = this.getCacheKey('smartfile', await smartfileArg.getHash(), wantedDimensionsArg);
|
const cacheKey = this.getCacheKey('smartfile', await smartfileArg.getHash(), wantedDimensionsArg);
|
||||||
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
const existingCacheEntry = await this.levelCache.retrieveCacheEntryByKey(cacheKey);
|
||||||
|
Reference in New Issue
Block a user