datasync-blob 1.0.1 → 1.0.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.
@@ -20,26 +20,60 @@ class DsBlob extends _react.Component {
20
20
  //console.log("imageSource = ",imageSource);
21
21
  var canvas = document.createElement('canvas'),
22
22
  context,
23
- maxWidth = 800,
24
- maxHeight = 800,
25
23
  width = imageSource.width,
26
24
  height = imageSource.height;
27
- if (width > height) {
28
- if (width > maxWidth) {
29
- height *= maxWidth / width;
30
- width = maxWidth;
25
+
26
+ //Exact size props are set
27
+ if (this.props.width && this.props.height) {
28
+ //Check image size
29
+ if (width > this.props.width || height > this.props.height) {
30
+ alert("L'image est trop grande, le format requis est " + this.props.width + "x" + this.props.height);
31
+ return;
31
32
  }
32
- } else {
33
- if (height > maxHeight) {
34
- width *= maxHeight / height;
35
- height = maxHeight;
33
+
34
+ //Check image size
35
+ if (width < this.props.width || height < this.props.height) {
36
+ alert("L'image est trop petite, le format requis est " + this.props.width + "x" + this.props.height);
37
+ return;
36
38
  }
37
39
  }
40
+
41
+ //Max size props are set
42
+ if (this.props.maxWidth && this.props.maxHeight) {
43
+ if (width > height) {
44
+ //Check resize is enabled
45
+ if (!this.props.reduceImage) {
46
+ alert("L'image est trop large, la largeur maximale est de " + this.props.maxWidth);
47
+ return;
48
+ }
49
+ if (width > this.props.maxWidth) {
50
+ height *= this.props.maxWidth / width;
51
+ width = this.props.maxWidth;
52
+ }
53
+ } else {
54
+ if (height > this.props.maxHeight) {
55
+ //Check resize is enabled
56
+ if (!this.props.reduceImage) {
57
+ alert("L'image est trop haute, la hauteur maximale est de " + this.props.maxHeight);
58
+ return;
59
+ }
60
+ width *= this.props.maxHeight / height;
61
+ height = this.props.maxHeight;
62
+ }
63
+ }
64
+ }
65
+
66
+ //Build 2d picture
38
67
  canvas.width = width;
39
68
  canvas.height = height;
40
69
  context = canvas.getContext('2d');
41
70
  context.drawImage(imageSource, 0, 0, width, height);
42
- let canvasData = canvas.toDataURL('image/jpg', 0.6); //Jpeg quality reduced from 0.8 down to 0.6
71
+
72
+ //Jpeg conversion
73
+ let jpegCompressionRatio = this.props.jpegQuality && this.props.jpegQuality > 0 && this.props.jpegQuality < 1 ? this.props.jpegQuality : 1;
74
+ let canvasData = canvas.toDataURL('image/jpg', jpegCompressionRatio); //Jpeg conversion
75
+
76
+ console.log("jpegCompressionRatio->", jpegCompressionRatio, " canvasData.length = ", canvasData.length);
43
77
  if (this.props.removebase64) {
44
78
  //remove base64 prefix if property is set
45
79
  this.props.uploadPicture({
@@ -81,7 +115,7 @@ class DsBlob extends _react.Component {
81
115
  onInputChange = e => {
82
116
  const errs = [];
83
117
  const files = Array.from(e.target.files);
84
- const types = ['image/png', 'image/jpeg'];
118
+ const types = ['image/png', 'image/jpeg', 'image/gif'];
85
119
  const _1Mo = 1024 * 1024;
86
120
  const SizeLimit = 9;
87
121
  console.clear();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "datasync-blob",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Datasync Blob component",
5
5
  "main": "./dist/components/DsBlob.js",
6
6
  "files": ["./dist"],