feat(core): add progressive JPEG support and fix Sharp format switching
This commit is contained in:
39
test/test.ts
39
test/test.ts
@@ -1,4 +1,4 @@
|
||||
import { expect, tap } from '@push.rocks/tapbundle';
|
||||
import { expect, tap } from '@git.zone/tstest/tapbundle';
|
||||
import * as smartjimp from '../ts/index.js';
|
||||
import * as smartfile from '@push.rocks/smartfile';
|
||||
|
||||
@@ -18,10 +18,45 @@ tap.test('should be able to create a master', async () => {
|
||||
tap.test('should be able to use jimp', async () => {
|
||||
const testSmartJimp = new smartjimp.SmartJimp({ mode: 'jimp'});
|
||||
const smartfileInstance = await smartfile.SmartFile.fromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80')
|
||||
const convertedAsset = await testSmartJimp.computeAssetVariation(smartfileInstance.contents, {
|
||||
const convertedAsset = await testSmartJimp.computeAssetVariation(smartfileInstance.contentBuffer, {
|
||||
format: 'png',
|
||||
});
|
||||
(await smartfile.SmartFile.fromBuffer('.nogit/result2.png', convertedAsset)).write();
|
||||
})
|
||||
|
||||
tap.test('should create progressive JPEG with Sharp', async () => {
|
||||
const testSmartJimp = new smartjimp.SmartJimp({ mode: 'sharp'});
|
||||
const smartfileInstance = await smartfile.SmartFile.fromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80')
|
||||
|
||||
// Create progressive JPEG
|
||||
const progressiveJpeg = await testSmartJimp.getFromSmartfile(smartfileInstance, {
|
||||
format: 'jpeg',
|
||||
progressive: true,
|
||||
width: 800
|
||||
});
|
||||
|
||||
expect(progressiveJpeg).toBeInstanceOf(Buffer);
|
||||
(await smartfile.SmartFile.fromBuffer('.nogit/progressive.jpg', progressiveJpeg)).write();
|
||||
})
|
||||
|
||||
tap.test('should convert PNG to progressive JPEG', async () => {
|
||||
const testSmartJimp = new smartjimp.SmartJimp({ mode: 'sharp'});
|
||||
|
||||
// First create a PNG
|
||||
const smartfileInstance = await smartfile.SmartFile.fromUrl('https://images.unsplash.com/photo-1673276628202-737bf3020ac2?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=3774&q=80')
|
||||
const pngBuffer = await testSmartJimp.computeAssetVariation(smartfileInstance.contentBuffer, {
|
||||
format: 'png',
|
||||
width: 500
|
||||
});
|
||||
|
||||
// Then convert it to progressive JPEG
|
||||
const progressiveJpeg = await testSmartJimp.computeAssetVariation(pngBuffer, {
|
||||
format: 'jpeg',
|
||||
progressive: true
|
||||
});
|
||||
|
||||
expect(progressiveJpeg).toBeInstanceOf(Buffer);
|
||||
(await smartfile.SmartFile.fromBuffer('.nogit/png-to-progressive.jpg', progressiveJpeg)).write();
|
||||
})
|
||||
|
||||
tap.start();
|
||||
|
Reference in New Issue
Block a user