ding-image-editor 3.15.8 → 3.15.10
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/dist/tui-image-editor.css +1 -1
- package/dist/tui-image-editor.js +31 -14
- package/dist/tui-image-editor.min.css +1 -1
- package/dist/tui-image-editor.min.js +2 -2
- package/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/js/component/freeDrawing copy.js +70 -11
- package/src/js/component/freeDrawing.js +28 -7
- package/src/js/component/text.js +6 -4
package/index.d.ts
CHANGED
package/package.json
CHANGED
@@ -18,6 +18,7 @@ class FreeDrawing extends Component {
|
|
18
18
|
* @type {number}
|
19
19
|
*/
|
20
20
|
this.width = 12;
|
21
|
+
this.pencilBrush = null;
|
21
22
|
|
22
23
|
/**
|
23
24
|
* fabric.Color instance for brush color
|
@@ -41,7 +42,7 @@ class FreeDrawing extends Component {
|
|
41
42
|
* @param {{width: ?number, color: ?string}} [setting] - Brush width & color
|
42
43
|
*/
|
43
44
|
start(setting) {
|
44
|
-
console.log(setting);
|
45
|
+
console.log('drawingsetting',setting);
|
45
46
|
if (setting?.mosaic) {
|
46
47
|
this.setMosaic(setting);
|
47
48
|
} else {
|
@@ -57,7 +58,14 @@ class FreeDrawing extends Component {
|
|
57
58
|
* @param {{width: ?number, color: ?string}} [setting] - Brush width & color
|
58
59
|
*/
|
59
60
|
setBrush(setting) {
|
60
|
-
const
|
61
|
+
const canvas = this.getCanvas()
|
62
|
+
if(!this.pencilBrush){
|
63
|
+
this.pencilBrush = new fabric.PencilBrush(canvas)
|
64
|
+
}
|
65
|
+
|
66
|
+
canvas.freeDrawingBrush = this.pencilBrush;
|
67
|
+
|
68
|
+
const brush = canvas.freeDrawingBrush;
|
61
69
|
|
62
70
|
setting = setting || {};
|
63
71
|
this.width = setting.width || this.width;
|
@@ -85,23 +93,74 @@ class FreeDrawing extends Component {
|
|
85
93
|
*/
|
86
94
|
setMosaic(setting) {
|
87
95
|
|
88
|
-
this.imageEditor = setting.imageEditor;
|
89
|
-
this.width = setting.width;
|
90
96
|
const canvas = this.getCanvas();
|
91
97
|
canvas.selection = false;
|
92
98
|
canvas.isDrawingMode = true;
|
99
|
+
const ctx = canvas.contextContainer;
|
100
|
+
const originalImageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
101
|
+
console.log(originalImageData)
|
102
|
+
|
103
|
+
let mosaicImageData = this.toMosaicImageData(originalImageData);
|
104
|
+
|
105
|
+
|
106
|
+
const patternCanvas = fabric.document.createElement('canvas');
|
107
|
+
const patternCtx = patternCanvas.getContext('2d');
|
108
|
+
patternCanvas.width = canvas.width
|
109
|
+
patternCanvas.height = canvas.height
|
110
|
+
patternCtx.putImageData(mosaicImageData,0,0)
|
93
111
|
|
94
|
-
const url = localStorage.getItem('mosaicImge')
|
95
|
-
console.log('mosic image',url)
|
96
|
-
var img222 = new Image();
|
97
|
-
img222.src = url;
|
98
112
|
var texturePatternBrush = new fabric.PatternBrush(canvas);
|
99
|
-
texturePatternBrush.source =
|
113
|
+
texturePatternBrush.source = patternCanvas;
|
100
114
|
canvas.freeDrawingBrush = texturePatternBrush;
|
101
|
-
canvas.freeDrawingBrush.width=
|
102
|
-
//canvas.on('mouse:down', this._handlers.mousedown);
|
115
|
+
canvas.freeDrawingBrush.width=setting.width
|
103
116
|
}
|
104
117
|
|
118
|
+
toMosaicImageData(imageData) {
|
119
|
+
// 定义马赛克方格大小(越大越模糊)
|
120
|
+
const suquareSize = 50;
|
121
|
+
let data = imageData.data;
|
122
|
+
const canvas ={ width:imageData.width,height:imageData.height}
|
123
|
+
//首先根据宽高遍历整个图片获取到对应的方格
|
124
|
+
for (let i = 0; i < canvas.height; i += suquareSize) {
|
125
|
+
for (let j = 0; j < canvas.width; j += suquareSize) {
|
126
|
+
let totalR = 0;
|
127
|
+
let totalG = 0;
|
128
|
+
let totalB = 0;
|
129
|
+
let totalA = 0;
|
130
|
+
let count = 0;
|
131
|
+
//遍历当前方格的每个像素将其RGBA值累加起来
|
132
|
+
for (let y = i; y < i + suquareSize && y < canvas.height; y++) {
|
133
|
+
for (let x = j; x < j + suquareSize && x < canvas.width; x++) {
|
134
|
+
//y * canvas.width + x就能计算出当前像素在整个图片中的索引
|
135
|
+
//再乘以4是因为imageData.data每个像素用4个值表示
|
136
|
+
//pixelIndex就是当前像素在imageData.data的起始索引也就是它的R值
|
137
|
+
let pixelIndex = (y * canvas.width + x) * 4;
|
138
|
+
totalR += data[pixelIndex];
|
139
|
+
totalG += data[pixelIndex + 1];
|
140
|
+
totalB += data[pixelIndex + 2];
|
141
|
+
totalA += data[pixelIndex + 3];
|
142
|
+
count++;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
let avgR = totalR / count;
|
146
|
+
let avgG = totalG / count;
|
147
|
+
let avgB = totalB / count;
|
148
|
+
let avgA = totalA / count;
|
149
|
+
// 遍历的逻辑与上面一模一样,这一步是将方格内的每个像素的RGBA值替换为平均值
|
150
|
+
for (let y = i; y < i + suquareSize && y < canvas.height; y++) {
|
151
|
+
for (let x = j; x < j + suquareSize && x < canvas.width; x++) {
|
152
|
+
let pixelIndex = (y * canvas.width + x) * 4;
|
153
|
+
data[pixelIndex] = avgR;
|
154
|
+
data[pixelIndex + 1] = avgG;
|
155
|
+
data[pixelIndex + 2] = avgB;
|
156
|
+
data[pixelIndex + 3] = avgA;
|
157
|
+
}
|
158
|
+
}
|
159
|
+
}
|
160
|
+
}
|
161
|
+
return imageData;
|
162
|
+
}
|
163
|
+
|
105
164
|
/**
|
106
165
|
* MouseDown event handler on canvas
|
107
166
|
* @param {{target: fabric.Object, e: MouseEvent}} fEvent - Fabric event object
|
@@ -18,6 +18,8 @@ class FreeDrawing extends Component {
|
|
18
18
|
* @type {number}
|
19
19
|
*/
|
20
20
|
this.width = 12;
|
21
|
+
this.pencilBrush = null;
|
22
|
+
this.patternBrush = null;
|
21
23
|
|
22
24
|
/**
|
23
25
|
* fabric.Color instance for brush color
|
@@ -57,7 +59,14 @@ class FreeDrawing extends Component {
|
|
57
59
|
* @param {{width: ?number, color: ?string}} [setting] - Brush width & color
|
58
60
|
*/
|
59
61
|
setBrush(setting) {
|
60
|
-
const
|
62
|
+
const canvas = this.getCanvas()
|
63
|
+
if(!this.pencilBrush){
|
64
|
+
this.pencilBrush = new fabric.PencilBrush(canvas)
|
65
|
+
}
|
66
|
+
|
67
|
+
canvas.freeDrawingBrush = this.pencilBrush;
|
68
|
+
|
69
|
+
const brush = canvas.freeDrawingBrush;
|
61
70
|
|
62
71
|
setting = setting || {};
|
63
72
|
this.width = setting.width || this.width;
|
@@ -85,11 +94,22 @@ class FreeDrawing extends Component {
|
|
85
94
|
*/
|
86
95
|
setMosaic(setting) {
|
87
96
|
|
88
|
-
// this.imageEditor = setting.imageEditor;
|
89
|
-
// this.width = setting.width;
|
90
97
|
const canvas = this.getCanvas();
|
91
98
|
canvas.selection = false;
|
92
99
|
canvas.isDrawingMode = true;
|
100
|
+
|
101
|
+
if(!this.patternBrush){
|
102
|
+
this.setPatternBrush()
|
103
|
+
}
|
104
|
+
|
105
|
+
canvas.freeDrawingBrush = this.patternBrush;
|
106
|
+
canvas.freeDrawingBrush.width=setting.width
|
107
|
+
}
|
108
|
+
|
109
|
+
setPatternBrush() {
|
110
|
+
|
111
|
+
const canvas = this.getCanvas();
|
112
|
+
|
93
113
|
const ctx = canvas.contextContainer;
|
94
114
|
const originalImageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
95
115
|
console.log(originalImageData)
|
@@ -103,10 +123,11 @@ class FreeDrawing extends Component {
|
|
103
123
|
patternCanvas.height = canvas.height
|
104
124
|
patternCtx.putImageData(mosaicImageData,0,0)
|
105
125
|
|
106
|
-
var
|
107
|
-
|
108
|
-
|
109
|
-
|
126
|
+
var patternBrush = new fabric.PatternBrush(canvas);
|
127
|
+
patternBrush.source = patternCanvas;
|
128
|
+
|
129
|
+
this.patternBrush = patternBrush
|
130
|
+
|
110
131
|
}
|
111
132
|
|
112
133
|
toMosaicImageData(imageData) {
|
package/src/js/component/text.js
CHANGED
@@ -502,9 +502,11 @@ class Text extends Component {
|
|
502
502
|
_onFabricMouseDown(fEvent) {
|
503
503
|
const obj = fEvent.target;
|
504
504
|
|
505
|
-
|
506
|
-
|
507
|
-
|
505
|
+
console.log(1111)
|
506
|
+
|
507
|
+
// if (obj && !obj.isType('text')) {
|
508
|
+
// return;
|
509
|
+
// }
|
508
510
|
|
509
511
|
// if (this.isPrevEditing) {
|
510
512
|
// this.isPrevEditing = false;
|
@@ -525,7 +527,7 @@ class Text extends Component {
|
|
525
527
|
const e = fEvent.e || {};
|
526
528
|
const originPointer = this.getCanvas().getPointer(e);
|
527
529
|
|
528
|
-
if (
|
530
|
+
if (true) {
|
529
531
|
this.fire(events.ADD_TEXT, {
|
530
532
|
originPosition: {
|
531
533
|
x: originPointer.x,
|