|
@@ -412,7 +412,9 @@ let zTool = {
|
|
// 在canvas上绘制原始图片
|
|
// 在canvas上绘制原始图片
|
|
ctx.drawImage(image, 0, 0);
|
|
ctx.drawImage(image, 0, 0);
|
|
// 添加水印文本
|
|
// 添加水印文本
|
|
- ctx.font = '15px Arial';
|
|
|
|
|
|
+ let size = Math.ceil(image.width*image.height /100000);
|
|
|
|
+
|
|
|
|
+ ctx.font = `${size}px Arial`;
|
|
ctx.fillStyle = 'rgb(228,233,229)';
|
|
ctx.fillStyle = 'rgb(228,233,229)';
|
|
const watermarkText = name; // 水印文本
|
|
const watermarkText = name; // 水印文本
|
|
const angle = 15 * Math.PI / 180; // 将15度转换为弧度
|
|
const angle = 15 * Math.PI / 180; // 将15度转换为弧度
|
|
@@ -474,11 +476,17 @@ let zTool = {
|
|
// ctx.restore(); // 恢复之前保存的绘图状态,避免影响后续绘图
|
|
// ctx.restore(); // 恢复之前保存的绘图状态,避免影响后续绘图
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
-
|
|
|
|
- // 将canvas转换为Blob对象
|
|
|
|
- canvas.toBlob(blob => {
|
|
|
|
- resolve(new File([blob], file.name, { type: 'image/jpg' }));
|
|
|
|
- }, 'image/jpg');
|
|
|
|
|
|
+ function _dataURLtoBlob(dataurl) {
|
|
|
|
+ var arr = dataurl.split(','), mime = arr[0].match(/:(.*?);/)[1],
|
|
|
|
+ bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
|
|
|
|
+ while(n--){
|
|
|
|
+ u8arr[n] = bstr.charCodeAt(n);
|
|
|
|
+ }
|
|
|
|
+ return new Blob([u8arr], {type:mime});
|
|
|
|
+ }
|
|
|
|
+ const dataurl2 = canvas.toDataURL('image/jpeg', 0.7);
|
|
|
|
+ const blob = _dataURLtoBlob(dataurl2)
|
|
|
|
+ return resolve(new File([blob], file.name, { type: 'image/jpg' }));
|
|
};
|
|
};
|
|
|
|
|
|
image.onerror = function () {
|
|
image.onerror = function () {
|