Commit cc4239c8 authored by Fabrizio Ruggeri's avatar Fabrizio Ruggeri
Browse files

Resolve "Update to latest sharp (0.22.x)"

parent 27e4d666
This diff is collapsed.
......@@ -46,7 +46,7 @@
"node-fetch": "^2.1.2",
"pino": "^5.5.0",
"pino-pretty": "^2.2.0",
"sharp": "^0.21.1",
"sharp": "^0.24.0",
"yargs": "12.0.2"
},
"devDependencies": {
......
......@@ -53,9 +53,10 @@ const overlayAlphaImage = async (duotoneImage, originalImage, opacity, format) =
.toBuffer();
return originalImage
.overlayWith(duotoneWithTransparency, {
.composite([{
input: duotoneWithTransparency,
raw: { width, height, channels: 4 },
})
}])
.raw()
.toBuffer({ resolveWithObject: true })
.then(({ data, info: raw }) => sharp(data, { raw }).toFormat(format));
......
......@@ -60,7 +60,7 @@ module.exports = (config) => {
if (!options.top && options.left !== undefined) {
options.top = 0;
}
return sharp.overlayWith(overlay, options);
return sharp.composite([{ input: overlay, ...options }]);
},
},
],
......
......@@ -3,7 +3,7 @@ const sharp = {
extract: jest.fn(async () => sharp),
flip: jest.fn(async () => sharp),
flop: jest.fn(async () => sharp),
overlayWith: jest.fn(() => sharp),
composite: jest.fn(() => sharp),
rotate: jest.fn(async () => sharp),
resize: jest.fn(async () => sharp),
jpeg: jest.fn(async () => sharp),
......@@ -35,7 +35,7 @@ const sharp = {
sharp.extract.mockClear();
sharp.flip.mockClear();
sharp.flop.mockClear();
sharp.overlayWith.mockClear();
sharp.composite.mockClear();
sharp.rotate.mockClear();
sharp.resize.mockClear();
sharp.jpeg.mockClear();
......
......@@ -32,11 +32,11 @@ describe('Overlay', () => {
await fn(sharp);
expect(mockImageGet).toHaveBeenCalledTimes(1);
expect(mockImageGet).toHaveBeenCalledWith('https://imageUrl');
expect(sharp.overlayWith).toHaveBeenCalledTimes(1);
expect(sharp.overlayWith).toHaveBeenCalledWith(
expect.any(Buffer),
{ tile: false },
);
expect(sharp.composite).toHaveBeenCalledTimes(1);
expect(sharp.composite).toHaveBeenCalledWith([{
input: expect.any(Buffer),
tile: false,
}]);
});
test('a gravity can be set', () => {
......@@ -55,11 +55,14 @@ describe('Overlay', () => {
test('overlay with gravity applied', async () => {
const { transformations: [{ fn }] } = overlay('https://imageUrl', 'gse');
await fn(sharp);
expect(sharp.overlayWith).toHaveBeenCalledTimes(1);
expect(sharp.overlayWith).toHaveBeenCalledWith(
expect.any(Buffer),
{ gravity: 'southeast', tile: false },
);
expect(sharp.composite).toHaveBeenCalledTimes(1);
expect(sharp.composite).toHaveBeenCalledWith([
{
input: expect.any(Buffer),
gravity: 'southeast',
tile: false,
},
]);
});
test('x and y can be set', async () => {
......@@ -78,11 +81,16 @@ describe('Overlay', () => {
test('overlay with x and y applied', async () => {
const { transformations: [{ fn }] } = overlay('https://imageUrl', 'x10', 'y20');
await fn(sharp);
expect(sharp.overlayWith).toHaveBeenCalledTimes(1);
expect(sharp.overlayWith).toHaveBeenCalledWith(
expect.any(Buffer),
{ left: 10, top: 20, tile: false },
);
expect(sharp.composite).toHaveBeenCalledTimes(1);
expect(sharp.composite).toHaveBeenCalledWith([
{
input: expect.any(Buffer),
left: 10,
top: 20,
tile: false,
},
]);
});
test('x and y can be set as percentage', async () => {
......@@ -101,11 +109,13 @@ describe('Overlay', () => {
test('overlay with x and y as percentage applied', async () => {
const { transformations: [{ fn }] } = overlay('https://imageUrl', 'x0.1', 'y0.2');
await fn(sharp);
expect(sharp.overlayWith).toHaveBeenCalledTimes(1);
expect(sharp.overlayWith).toHaveBeenCalledWith(
expect.any(Buffer),
{ left: 64, top: 96, tile: false },
);
expect(sharp.composite).toHaveBeenCalledTimes(1);
expect(sharp.composite).toHaveBeenCalledWith([{
input: expect.any(Buffer),
left: 64,
top: 96,
tile: false,
}]);
});
test('only x can be set. y will be 0', async () => {
......@@ -124,11 +134,13 @@ describe('Overlay', () => {
test('overlay with x applied', async () => {
const { transformations: [{ fn }] } = overlay('https://imageUrl', 'x10');
await fn(sharp);
expect(sharp.overlayWith).toHaveBeenCalledTimes(1);
expect(sharp.overlayWith).toHaveBeenCalledWith(
expect.any(Buffer),
{ left: 10, top: 0, tile: false },
);
expect(sharp.composite).toHaveBeenCalledTimes(1);
expect(sharp.composite).toHaveBeenCalledWith([{
input: expect.any(Buffer),
left: 10,
top: 0,
tile: false,
}]);
});
test('only y can be set. x will be 0', async () => {
......@@ -147,11 +159,13 @@ describe('Overlay', () => {
test('overlay with y applied', async () => {
const { transformations: [{ fn }] } = overlay('https://imageUrl', 'y40');
await fn(sharp);
expect(sharp.overlayWith).toHaveBeenCalledTimes(1);
expect(sharp.overlayWith).toHaveBeenCalledWith(
expect.any(Buffer),
{ left: 0, top: 40, tile: false },
);
expect(sharp.composite).toHaveBeenCalledTimes(1);
expect(sharp.composite).toHaveBeenCalledWith([{
input: expect.any(Buffer),
left: 0,
top: 40,
tile: false,
}]);
});
test('watermark can be set', async () => {
......@@ -170,11 +184,11 @@ describe('Overlay', () => {
test('overlay with watermark applied', async () => {
const { transformations: [{ fn }] } = overlay('https://imageUrl', 'watermark');
await fn(sharp);
expect(sharp.overlayWith).toHaveBeenCalledTimes(1);
expect(sharp.overlayWith).toHaveBeenCalledWith(
expect.any(Buffer),
{ tile: true },
);
expect(sharp.composite).toHaveBeenCalledTimes(1);
expect(sharp.composite).toHaveBeenCalledWith([{
input: expect.any(Buffer),
tile: true,
}]);
});
test('if the image is not retrieved, an error is returned', async () => {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment