@zhaoshijun/compress 1.2.3 → 1.2.4
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 +36 -28
package/package.json
CHANGED
package/src/core/watermark.js
CHANGED
|
@@ -218,21 +218,25 @@ export async function addImageWatermark(sharpInstance, options) {
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
if (opacity < 1) {
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
watermarkImage = sharp(data, {
|
|
230
|
-
raw: {
|
|
231
|
-
width: info.width,
|
|
232
|
-
height: info.height,
|
|
233
|
-
channels: 4
|
|
221
|
+
try {
|
|
222
|
+
const tempBuffer = await watermarkImage.ensureAlpha().png().toBuffer();
|
|
223
|
+
const tempSharp = sharp(tempBuffer);
|
|
224
|
+
const { data, info } = await tempSharp.raw().toBuffer({ resolveWithObject: true });
|
|
225
|
+
|
|
226
|
+
for (let i = 3; i < data.length; i += 4) {
|
|
227
|
+
data[i] = Math.floor(data[i] * opacity);
|
|
234
228
|
}
|
|
235
|
-
|
|
229
|
+
|
|
230
|
+
watermarkImage = sharp(data, {
|
|
231
|
+
raw: {
|
|
232
|
+
width: info.width,
|
|
233
|
+
height: info.height,
|
|
234
|
+
channels: 4
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
} catch (error) {
|
|
238
|
+
console.warn('Failed to apply opacity, using original image:', error.message);
|
|
239
|
+
}
|
|
236
240
|
}
|
|
237
241
|
|
|
238
242
|
const finalWatermarkBuffer = await watermarkImage.toBuffer();
|
|
@@ -339,21 +343,25 @@ export async function addTiledImageWatermark(sharpInstance, options, providedMet
|
|
|
339
343
|
}
|
|
340
344
|
|
|
341
345
|
if (opacity < 1) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
watermarkImage = sharp(data, {
|
|
351
|
-
raw: {
|
|
352
|
-
width: info.width,
|
|
353
|
-
height: info.height,
|
|
354
|
-
channels: 4
|
|
346
|
+
try {
|
|
347
|
+
const tempBuffer = await watermarkImage.ensureAlpha().png().toBuffer();
|
|
348
|
+
const tempSharp = sharp(tempBuffer);
|
|
349
|
+
const { data, info } = await tempSharp.raw().toBuffer({ resolveWithObject: true });
|
|
350
|
+
|
|
351
|
+
for (let i = 3; i < data.length; i += 4) {
|
|
352
|
+
data[i] = Math.floor(data[i] * opacity);
|
|
355
353
|
}
|
|
356
|
-
|
|
354
|
+
|
|
355
|
+
watermarkImage = sharp(data, {
|
|
356
|
+
raw: {
|
|
357
|
+
width: info.width,
|
|
358
|
+
height: info.height,
|
|
359
|
+
channels: 4
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
} catch (error) {
|
|
363
|
+
console.warn('Failed to apply opacity, using original image:', error.message);
|
|
364
|
+
}
|
|
357
365
|
}
|
|
358
366
|
|
|
359
367
|
if (angle !== 0) {
|