@zhaoshijun/compress 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/core/watermark.js +13 -13
package/package.json
CHANGED
package/src/core/watermark.js
CHANGED
|
@@ -217,8 +217,8 @@ export async function addImageWatermark(sharpInstance, options) {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
if (opacity < 1) {
|
|
220
|
-
const
|
|
221
|
-
watermarkImage = sharp(
|
|
220
|
+
const tempBuffer = await watermarkImage.toBuffer();
|
|
221
|
+
watermarkImage = sharp(tempBuffer).ensureAlpha();
|
|
222
222
|
const { data } = await watermarkImage.raw().toBuffer({ resolveWithObject: true });
|
|
223
223
|
|
|
224
224
|
for (let i = 3; i < data.length; i += 4) {
|
|
@@ -234,8 +234,8 @@ export async function addImageWatermark(sharpInstance, options) {
|
|
|
234
234
|
});
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
-
const
|
|
238
|
-
const finalWatermarkMeta = await sharp(
|
|
237
|
+
const finalWatermarkBuffer = await watermarkImage.toBuffer();
|
|
238
|
+
const finalWatermarkMeta = await sharp(finalWatermarkBuffer).metadata();
|
|
239
239
|
|
|
240
240
|
let compositeX = x;
|
|
241
241
|
let compositeY = y;
|
|
@@ -267,7 +267,7 @@ export async function addImageWatermark(sharpInstance, options) {
|
|
|
267
267
|
|
|
268
268
|
const result = await sharpInstance
|
|
269
269
|
.composite([{
|
|
270
|
-
input:
|
|
270
|
+
input: finalWatermarkBuffer,
|
|
271
271
|
left: compositeX,
|
|
272
272
|
top: compositeY,
|
|
273
273
|
blend: 'over'
|
|
@@ -335,8 +335,8 @@ export async function addTiledImageWatermark(sharpInstance, options, providedMet
|
|
|
335
335
|
}
|
|
336
336
|
|
|
337
337
|
if (opacity < 1) {
|
|
338
|
-
const
|
|
339
|
-
watermarkImage = sharp(
|
|
338
|
+
const tempBuffer = await watermarkImage.toBuffer();
|
|
339
|
+
watermarkImage = sharp(tempBuffer).ensureAlpha();
|
|
340
340
|
const { data, info } = await watermarkImage.raw().toBuffer({ resolveWithObject: true });
|
|
341
341
|
|
|
342
342
|
for (let i = 3; i < data.length; i += 4) {
|
|
@@ -353,21 +353,21 @@ export async function addTiledImageWatermark(sharpInstance, options, providedMet
|
|
|
353
353
|
}
|
|
354
354
|
|
|
355
355
|
if (angle !== 0) {
|
|
356
|
-
const
|
|
357
|
-
const rotatedMeta = await sharp(
|
|
356
|
+
const rotatedBuffer = await watermarkImage.toBuffer();
|
|
357
|
+
const rotatedMeta = await sharp(rotatedBuffer).metadata();
|
|
358
358
|
const radians = angle * Math.PI / 180;
|
|
359
359
|
const cos = Math.abs(Math.cos(radians));
|
|
360
360
|
const sin = Math.abs(Math.sin(radians));
|
|
361
361
|
const newWidth = Math.ceil(rotatedMeta.width * cos + rotatedMeta.height * sin);
|
|
362
362
|
const newHeight = Math.ceil(rotatedMeta.width * sin + rotatedMeta.height * cos);
|
|
363
363
|
|
|
364
|
-
watermarkImage = sharp(
|
|
364
|
+
watermarkImage = sharp(rotatedBuffer).rotate(angle, {
|
|
365
365
|
background: { r: 0, g: 0, b: 0, alpha: 0 }
|
|
366
366
|
}).resize(newWidth, newHeight);
|
|
367
367
|
}
|
|
368
368
|
|
|
369
|
-
const
|
|
370
|
-
const finalWatermarkMeta = await sharp(
|
|
369
|
+
const finalWatermarkBuffer = await watermarkImage.toBuffer();
|
|
370
|
+
const finalWatermarkMeta = await sharp(finalWatermarkBuffer).metadata();
|
|
371
371
|
|
|
372
372
|
const cols = Math.ceil(metadata.width / spacingX) + 1;
|
|
373
373
|
const rows = Math.ceil(metadata.height / spacingY) + 1;
|
|
@@ -376,7 +376,7 @@ export async function addTiledImageWatermark(sharpInstance, options, providedMet
|
|
|
376
376
|
for (let row = 0; row < rows; row++) {
|
|
377
377
|
for (let col = 0; col < cols; col++) {
|
|
378
378
|
composites.push({
|
|
379
|
-
input:
|
|
379
|
+
input: finalWatermarkBuffer,
|
|
380
380
|
left: col * spacingX,
|
|
381
381
|
top: row * spacingY
|
|
382
382
|
});
|