kfb-view 3.0.2 → 3.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "kfb-view",
3
3
  "description": "一个在线kfb的阅片软件",
4
- "version": "3.0.2",
4
+ "version": "3.0.4",
5
5
  "author": "qifeng.fan <qifeng.fan@hzztai.com>",
6
6
  "license": "MIT",
7
7
  "main": "lib/kfb-view.js",
@@ -325,19 +325,19 @@ export class Navigator extends EventEmitter {
325
325
  const imgHeight = img.height;
326
326
  let scale = 1;
327
327
  if (imgWidth >= imgHeight) {
328
- scale = imgHeight / this.height;
329
- const trueWidth = imgWidth / scale;
330
- canvas.height = this.height;
331
- canvas.width = trueWidth;
332
- ctx.drawImage(img, 0, 0, trueWidth, canvas.height);
333
- }
334
- if (imgHeight > imgWidth) {
335
328
  scale = imgWidth / this.width;
336
329
  const trueHeight = imgHeight / scale;
337
330
  canvas.width = this.width;
338
331
  canvas.height = trueHeight;
339
332
  ctx.drawImage(img, 0, 0, canvas.width, trueHeight);
340
333
  }
334
+ if (imgHeight > imgWidth) {
335
+ scale = imgHeight / this.height;
336
+ const trueWidth = imgWidth / scale;
337
+ canvas.height = this.height;
338
+ canvas.width = trueWidth;
339
+ ctx.drawImage(img, 0, 0, trueWidth, canvas.height);
340
+ }
341
341
  this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
342
342
  const colorCanvas = this.element.getElementsByClassName(
343
343
  'navigator-color-rect')[0];
@@ -358,14 +358,6 @@ export class Navigator extends EventEmitter {
358
358
  const imgHeight = img.height;
359
359
  let scale = 1;
360
360
  if (imgWidth >= imgHeight) {
361
- scale = imgHeight / this.height;
362
- const trueWidth = imgWidth / scale;
363
- this.canvas.height = this.height;
364
- this.canvas.width = trueWidth;
365
- ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
366
- ctx.drawImage(img, 0, 0, trueWidth, this.canvas.height);
367
- }
368
- if (imgHeight > imgWidth) {
369
361
  scale = imgWidth / this.width;
370
362
  const trueHeight = imgHeight / scale;
371
363
  this.canvas.width = this.width;
@@ -373,6 +365,14 @@ export class Navigator extends EventEmitter {
373
365
  ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
374
366
  ctx.drawImage(img, 0, 0, this.canvas.width, trueHeight);
375
367
  }
368
+ if (imgHeight > imgWidth) {
369
+ scale = imgHeight / this.height;
370
+ const trueWidth = imgWidth / scale;
371
+ this.canvas.height = this.height;
372
+ this.canvas.width = trueWidth;
373
+ ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
374
+ ctx.drawImage(img, 0, 0, trueWidth, this.canvas.height);
375
+ }
376
376
  this.setViewRect(this.element.getElementsByClassName('view-rect')[0]);
377
377
  const colorCanvas = this.element.getElementsByClassName(
378
378
  'navigator-color-rect')[0];
@@ -29,7 +29,12 @@ export class Tailoring extends ViewerCommon {
29
29
  this.movePointIndex = -1;
30
30
  this.color = '#FFF';
31
31
  this.contents = [];
32
- this.imageType = 'jpeg';
32
+ this.options = {
33
+ suffix: 'jpeg',
34
+ quality: 0.92,
35
+ resolution: 1200,
36
+ ...this.options,
37
+ };
33
38
  }
34
39
 
35
40
  init({
@@ -40,11 +45,9 @@ export class Tailoring extends ViewerCommon {
40
45
  color,
41
46
  now = false,
42
47
  contents = [],
43
- suffix = 'jpeg',
44
48
  }) {
45
49
  this.isInTailoring = true;
46
50
  this.movePointIndex = -1;
47
- this.imageType = suffix;
48
51
  const pointList = getRectPoint({x: left, y: top},
49
52
  {x: left + width, y: top + height});
50
53
  this.tailoringPoints = [
@@ -296,10 +299,20 @@ export class Tailoring extends ViewerCommon {
296
299
  const imageData =
297
300
  ctx.getImageData(
298
301
  startPoint.x * radioX, startPoint.y * radioY, disWidth, disHeight);
302
+ for (let i = 0; i < imageData.data.length; i += 4) {
303
+ if (imageData.data[i + 3] === 0) {
304
+ imageData.data[i] = 255;
305
+ imageData.data[i + 1] = 255;
306
+ imageData.data[i + 2] = 255;
307
+ imageData.data[i + 3] = 255;
308
+ }
309
+ }
299
310
  const copyCanvas = document.createElement('canvas');
300
311
  copyCanvas.width = disWidth;
301
312
  copyCanvas.height = disHeight;
302
313
  const copyCtx = copyCanvas.getContext('2d');
314
+ copyCtx.fillstyle = '#fff';
315
+ copyCtx.fillRect(0, 0, copyCanvas.width, copyCanvas.height);
303
316
  copyCtx.putImageData(imageData, 0, 0, 0, 0, disWidth, disHeight);
304
317
  const shapeCanvas = this.kv.shape?.canvas;
305
318
  if (shapeCanvas) {
@@ -307,7 +320,22 @@ export class Tailoring extends ViewerCommon {
307
320
  startPoint.y * radioY, disWidth, disHeight, 0, 0, disWidth,
308
321
  disHeight);
309
322
  }
310
- return copyCanvas.toDataURL(`image/${this.imageType || 'jpeg'}`);
323
+ if (copyCanvas.width > this.options.resolution) {
324
+ const maxCanvas = document.createElement('canvas');
325
+ maxCanvas.width = this.options.resolution;
326
+ maxCanvas.height = this.options.resolution / copyCanvas.width *
327
+ copyCanvas.height;
328
+ const maxCtx = maxCanvas.getContext('2d');
329
+ maxCtx.fillstyle = '#fff';
330
+ maxCtx.fillRect(0, 0, maxCanvas.width, maxCanvas.height);
331
+ maxCtx.drawImage(copyCanvas, 0, 0, copyCanvas.width, copyCanvas.height,
332
+ 0, 0, maxCanvas.width, maxCanvas.height);
333
+ return maxCanvas.toDataURL(`image/${this.options.suffix || 'jpeg'}`,
334
+ this.options.quality);
335
+ } else {
336
+ return copyCanvas.toDataURL(`image/${this.options.suffix || 'jpeg'}`,
337
+ this.options.quality);
338
+ }
311
339
  } catch (e) {
312
340
  console.error(e);
313
341
  }
package/src/view.js CHANGED
@@ -51,6 +51,9 @@ export default class KfbView extends EventEmitter {
51
51
  * @param {boolean=} config.rotation.disabled 是否禁用旋转
52
52
  * @param {Object} config.tailoring 裁剪图像参数
53
53
  * @param {boolean=} config.tailoring.disabled 是否禁用裁剪
54
+ * @param {string=} config.tailoring.suffix 截图后缀
55
+ * @param {number=} config.tailoring.quality 截图的质量
56
+ * @param {number=} config.tailoring.resolution 分辨率
54
57
  * @param {Object} config.shape 显示标注图形
55
58
  * @param {boolean=} config.shape.disabled 是否禁用标注
56
59
  * @param {Object} config.board 标注参数