Commit 57c6249e0743d117aa189c6247f35a08def82860

Authored by OpenWapp Developer
1 parent 6ffe785644

Reducing the quality and size for thumbs

Showing 3 changed files with 12 additions and 7 deletions

app/scripts/utils/thumbnail.js View file @ 57c6249
... ... @@ -10,6 +10,7 @@
10 10 generate: function (imageBlob, callback, options) {
11 11 options = options || {};
12 12 var maxSize = this.maxSize || DEFAULT_MAX_SIZE;
  13 + var quality = options.quality || 0.8;
13 14  
14 15 var fileReader = new FileReader();
15 16 fileReader.readAsDataURL(imageBlob);
... ... @@ -31,7 +32,7 @@
31 32 ctx.drawImage(img, 0, 0, width * scale, height * scale);
32 33  
33 34 if (options.asBlob) {
34   - c.toBlob(callback.bind(null, null), 'image/jpeg');
  35 + c.toBlob(callback.bind(null, null), 'image/jpeg', quality);
35 36 } else {
36 37 callback(null, c.toDataURL('image/jpeg').split('base64,')[1]);
37 38 }
app/scripts/views/group-profile.js View file @ 57c6249
... ... @@ -31,7 +31,7 @@
31 31  
32 32 PICTURE_MAX_SIZE: 640,
33 33  
34   - THUMB_MAX_SIZE: 180,
  34 + THUMB_MAX_SIZE: 96,
35 35  
36 36 initialize: function () {
37 37 this.picture = this.model.get('photo');
... ... @@ -226,6 +226,7 @@
226 226 });
227 227  
228 228 var _this = this;
  229 + var quality = global.client.getProperty('image_quality');
229 230 requestPicture.onsuccess = function () {
230 231 var picture = requestPicture.result.blob;
231 232 _this.isGroupPictureDirty = true;
... ... @@ -240,8 +241,8 @@
240 241 Thumbnail.generate(picture, function (err, thumb) {
241 242 if (err) { return; }
242 243 _this.thumb = thumb;
243   - }, { asBlob: true });
244   - }, { asBlob: true });
  244 + }, { asBlob: true, quality: quality / 2 });
  245 + }, { asBlob: true, quality: quality });
245 246 };
246 247  
247 248 requestPicture.onerror = function () {
app/scripts/views/profile.js View file @ 57c6249
... ... @@ -22,7 +22,7 @@
22 22  
23 23 PICTURE_MAX_SIZE: 640,
24 24  
25   - THUMB_MAX_SIZE: 180,
  25 + THUMB_MAX_SIZE: 96,
26 26  
27 27 initialize: function () {
28 28 this.picture = this.model.get('photo');
29 29  
30 30  
31 31  
... ... @@ -131,13 +131,16 @@
131 131 },
132 132  
133 133 generatePicture: function (picture, callback) {
  134 + var quality = global.client.getProperty('image_quality');
134 135 Thumbnail.setMaxSize(this.PICTURE_MAX_SIZE);
135   - Thumbnail.generate(picture, callback, { asBlob: true });
  136 + Thumbnail.generate(picture, callback, { asBlob: true, quality: quality });
136 137 },
137 138  
138 139 generateThumbnail: function (picture, callback) {
  140 + var quality = global.client.getProperty('image_quality');
139 141 Thumbnail.setMaxSize(this.THUMB_MAX_SIZE);
140   - Thumbnail.generate(picture, callback, { asBlob: true });
  142 + Thumbnail
  143 + .generate(picture, callback, { asBlob: true, quality: quality / 2 });
141 144 },
142 145  
143 146 showSelect: function () {