Sherry 1 yıl önce
ebeveyn
işleme
311c26b2f7

+ 3
- 0
src/fe/index.html Dosyayı Görüntüle

@@ -494,12 +494,15 @@
494 494
     </div>
495 495
   </div>
496 496
 
497
+  <!-- <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script> -->
497 498
   <script src="lib/jquery-3.5.1.min.js"></script>
498 499
   <script src="https://cdn.jsdelivr.net/npm/bootstrap@4.1.3/dist/js/bootstrap.min.js"
499 500
     integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy"
500 501
     crossorigin="anonymous"></script>
501 502
   <script charset="utf-8" src="https://static.line-scdn.net/liff/edge/2/sdk.js"></script>
502 503
   <script src="./lib/gsap.min.js"></script>
504
+  <script src="./lib/exif.js"></script>
505
+  <script src="./lib/photoHelper.js"></script>
503 506
   <script src="js/utlis.js"></script>
504 507
   <script src="./js/services/userModel.js"></script>
505 508
   <script src="./js/services/index.js"></script>

+ 1
- 2
src/fe/js/base.js Dosyayı Görüntüle

@@ -20,8 +20,6 @@ base = function () {
20 20
 			userProfile = profile;
21 21
 			getProfile();
22 22
 
23
-			register.LinePicHandler(profile.pictureUrl)
24
-
25 23
 			// 正式用 記得開
26 24
 			GameService.getInstanse().userLogin()
27 25
 				.then(_res => {
@@ -39,6 +37,7 @@ base = function () {
39 37
 					console.log("userData: ",userData)
40 38
 					
41 39
 					if(userData === null) {
40
+						register.LinePicHandler(profile.pictureUrl)
42 41
 						sectionFadeIn(".register");
43 42
 					}else {
44 43
 						sectionFadeIn(".passport");

+ 72
- 15
src/fe/js/register.js Dosyayı Görüntüle

@@ -114,6 +114,7 @@ register = function () {
114 114
 		const imagePreview = $('.photo__img');
115 115
 		// console.log(fileInput.id)
116 116
 
117
+		var templeteHelper = new photoHelper();
117 118
 
118 119
 		fileInputs.forEach((fileInput)=> {
119 120
 			// 當選擇圖片後,顯示圖片的預覽
@@ -123,25 +124,44 @@ register = function () {
123 124
 				const selectedFile = fileInput.files[0];
124 125
 
125 126
 				if(selectedFile) {
126
-					const reader = new FileReader();
127
-					reader.onload = function(e) {
128
-						// 移除 data:image/jpeg;base64,
129
-						// customBase64Data = e.target.result.split(",")[1];
130
-
131
-						customBase64Data = e.target.result;
132
-						finalase64Data = customBase64Data;
133
-						// console.log(e.target)
134
-						const img = new Image();
135
-						img.src = e.target.result;
136
-						imagePreview.html("");
137
-						imagePreview.append(img);
138
-
139
-						// console.log(finalase64Data)
127
+
128
+					if(fileInput.id == 'fileInput1') {
129
+						templeteHelper.loadFile('#fileInput1',function (_photoData) {
130
+							console.log('fileInput1 has loaded.');
131
+							templateData = _photoData;
132
+							
133
+							finalase64Data = templateData;
134
+							console.log(finalase64Data)
135
+							
136
+							const img = new Image();
137
+							img.src = templateData;
138
+							imagePreview.html("");
139
+							imagePreview.append(img);
140
+							// $('.templete_output').attr('src', templateData);
141
+						});
140 142
 					}
141
-					reader.readAsDataURL(selectedFile);
143
+
144
+					if(fileInput.id == 'fileInput2') {
145
+						templeteHelper.loadFile('#fileInput2',function (_photoData) {
146
+							console.log('fileInput2 has loaded.');
147
+							templateData = _photoData;
148
+							
149
+							finalase64Data = templateData;
150
+							console.log(finalase64Data)
151
+	
152
+							const img = new Image();
153
+							img.src = templateData;
154
+							imagePreview.html("");
155
+							imagePreview.append(img);
156
+							// $('.templete_output').attr('src', templateData);
157
+						});
158
+					}
159
+					
160
+
142 161
 				}else {
143 162
 					LinePicHandler(linePicUrl);
144 163
 				}
164
+
145 165
 				if(fileInput.id == 'fileInput2') {
146 166
 					setTimeout(()=>{
147 167
 						console.log(finalase64Data)
@@ -151,6 +171,43 @@ register = function () {
151 171
 				}
152 172
 			});
153 173
 		});
174
+
175
+		// fileInputs.forEach((fileInput)=> {
176
+		// 	// 當選擇圖片後,顯示圖片的預覽
177
+		// 	fileInput.addEventListener("change", function(e){
178
+		// 		console.log(fileInput.id)
179
+
180
+		// 		const selectedFile = fileInput.files[0];
181
+
182
+		// 		if(selectedFile) {
183
+		// 			const reader = new FileReader();
184
+		// 			reader.onload = function(e) {
185
+		// 				// 移除 data:image/jpeg;base64,
186
+		// 				// customBase64Data = e.target.result.split(",")[1];
187
+
188
+		// 				customBase64Data = e.target.result;
189
+		// 				finalase64Data = customBase64Data;
190
+		// 				// console.log(e.target)
191
+		// 				const img = new Image();
192
+		// 				img.src = e.target.result;
193
+		// 				imagePreview.html("");
194
+		// 				imagePreview.append(img);
195
+
196
+		// 				// console.log(finalase64Data)
197
+		// 			}
198
+		// 			reader.readAsDataURL(selectedFile);
199
+		// 		}else {
200
+		// 			LinePicHandler(linePicUrl);
201
+		// 		}
202
+		// 		if(fileInput.id == 'fileInput2') {
203
+		// 			setTimeout(()=>{
204
+		// 				console.log(finalase64Data)
205
+		// 				sendBase64DataToApi(finalase64Data);
206
+		// 			}, 200);
207
+					
208
+		// 		}
209
+		// 	});
210
+		// });
154 211
 	}
155 212
 
156 213
 	// 送出圖片

+ 1
- 1
src/fe/js/services/index.js Dosyayı Görüntüle

@@ -16,7 +16,7 @@ function Service() {
16 16
       
17 17
       // // 測試用資料
18 18
       // const profile = {
19
-      //   userId: "Ua89aacd560a328ece0fec5584435046d",
19
+      //   userId: "Ua89aacd560a328ece0fec5584435046f",
20 20
       //   displayName: "Tim",
21 21
       //   pictureUrl: "https://sprofile.line-scdn.net/0hAvrrYLRRHllfCwoU_RtgJi9bHTN8ekdLdWRZPmJYQGxnPFwLdG5Za29YSTkyb1AGID9XbzoLEmlTGGk_QV3ibVg7QG5mOVANdm5Uug",
22 22
       // }

+ 1059
- 0
src/fe/lib/exif.js
Dosya farkı çok büyük olduğundan ihmal edildi
Dosyayı Görüntüle


+ 126
- 0
src/fe/lib/photoHelper.js Dosyayı Görüntüle

@@ -0,0 +1,126 @@
1
+/**
2
+ *
3
+ * @authors Eric Hsiao
4
+ *
5
+ */
6
+
7
+var photoHelper = function () {
8
+
9
+  //private menbers
10
+  var photoData;
11
+  var maxHeight = 1200;
12
+
13
+  //private methods
14
+  function init() {
15
+    console.log('photoHelper is loaded.');
16
+  }
17
+
18
+  function loadFile(_input,_callback) {
19
+    // var file = document.querySelector('input[type=file]').files[0];
20
+    var file = $(_input)[0].files[0];
21
+
22
+    ImageHelper.resizeAndRotateImage(file,maxHeight,function(resizeImageObj){
23
+      // var newImage = new Image();
24
+      // newImage.src = resizeImageObj;
25
+      _callback(resizeImageObj);
26
+    });
27
+  }
28
+
29
+  var ImageHelper = {
30
+    resizeAndRotateImage: function (inImageSource, inMaxLength, inSuccessCallback) {
31
+      var reader = new FileReader();
32
+      reader.readAsDataURL(inImageSource);
33
+      reader.onload = function (e) {
34
+        var canvas = document.createElement('canvas');
35
+        var ctx = canvas.getContext("2d");
36
+        var img = new Image();
37
+        img.onload = function () {
38
+          //設定長邊上限值
39
+          var max_Length = inMaxLength;
40
+
41
+          var imgWidth = img.width;
42
+          var imgHeight = img.height;
43
+
44
+          if (imgWidth > imgHeight) {
45
+            if (imgHeight > max_Length) {
46
+              imgWidth = Math.round(imgWidth *= max_Length / imgHeight);
47
+              imgHeight = max_Length;
48
+            }
49
+          } else {
50
+            if (imgWidth > max_Length) {
51
+              imgHeight = Math.round(imgHeight *= max_Length / imgWidth);
52
+              imgWidth = max_Length;
53
+            }
54
+          }
55
+
56
+          canvas.width = imgWidth;
57
+          canvas.height = imgHeight;
58
+
59
+          var that = this;
60
+          EXIF.getData(img, function () {
61
+            var orientation = EXIF.getTag(that, 'Orientation');
62
+            // alert(orientation);
63
+
64
+            if (orientation == 6 || orientation == 8 || orientation == 3) {
65
+              var rotateAngle = 0;
66
+
67
+              switch (orientation) {
68
+                case 3:
69
+                  rotateAngle = 180;
70
+                  break;
71
+                case 6:
72
+                  rotateAngle = 90;
73
+                  canvas.width = imgHeight;
74
+                  canvas.height = imgWidth;
75
+                  break;
76
+                case 8:
77
+                  rotateAngle = -90;
78
+                  canvas.width = imgHeight;
79
+                  canvas.height = imgWidth;
80
+                  break;
81
+              }
82
+
83
+              var x = canvas.width / 2;
84
+              var y = canvas.height / 2;
85
+
86
+              ctx.translate(x, y);
87
+              ctx.rotate(rotateAngle * Math.PI / 180);
88
+
89
+              ctx.drawImage(img, (-imgWidth / 2), (-imgHeight / 2), imgWidth, imgHeight);
90
+              console.log(imgWidth + ', ' + imgHeight);
91
+            }
92
+            else {
93
+              ctx.drawImage(img, 0, 0, imgWidth, imgHeight);
94
+              console.log(imgWidth + ', ' + imgHeight);
95
+            }
96
+          });
97
+
98
+
99
+          var res = canvas.toDataURL("image/jpeg", 0.9);
100
+
101
+          inSuccessCallback(res);
102
+        };
103
+
104
+        img.src = e.target.result;
105
+      };
106
+    }
107
+  };
108
+
109
+  //constructor
110
+
111
+  {
112
+    $(document).ready(function () {
113
+      init();
114
+    });
115
+  }
116
+
117
+  //public
118
+
119
+  return {
120
+    loadFile: function (_input,_callback) {
121
+      loadFile(_input,_callback);
122
+    }
123
+  };
124
+};
125
+
126
+