Browse Source

Merge branch 'master' into develop

Gaël Métais 7 years ago
parent
commit
1eda5e5860

+ 2 - 2
front/src/js/directives/offendersDirectives.js

@@ -751,7 +751,7 @@
         }
         }
 
 
         function onDetailsClick(row) {
         function onDetailsClick(row) {
-            // Close if it's alreay open
+            // Close if it's already open
             if (row.classList.contains('showDetails')) {
             if (row.classList.contains('showDetails')) {
                 closeDetails(row);
                 closeDetails(row);
                 return;
                 return;
@@ -924,4 +924,4 @@
         };
         };
     });
     });
 
 
-})();
+})();

+ 1 - 1
lib/metadata/policies.js

@@ -893,7 +893,7 @@ var policies = {
     "totalWeight": {
     "totalWeight": {
         "tool": "redownload",
         "tool": "redownload",
         "label": "Total weight",
         "label": "Total weight",
-        "message": "<p>The weight is of course very important if you want the page to load fast. Try to stay under 1MB, which is alreay very long to download over a slow connection.</p><p>Please note that Yellow Lab Tools' engine (PhantomJS) is not compatible with image srcset (unless you use a polyfill). This can lead to incorrect page weight.</p>",
+        "message": "<p>The weight is of course very important if you want the page to load fast. Try to stay under 1MB, which is already very long to download over a slow connection.</p><p>Please note that Yellow Lab Tools' engine (PhantomJS) is not compatible with image srcset (unless you use a polyfill). This can lead to incorrect page weight.</p>",
         "isOkThreshold": 716800,
         "isOkThreshold": 716800,
         "isBadThreshold": 2097152,
         "isBadThreshold": 2097152,
         "isAbnormalThreshold": 3145728,
         "isAbnormalThreshold": 3145728,

+ 8 - 8
lib/screenshotHandler.js

@@ -1,5 +1,5 @@
 var debug       = require('debug')('ylt:screenshotHandler');
 var debug       = require('debug')('ylt:screenshotHandler');
-var lwip        = require('lwip');
+var Jimp        = require('jimp');
 var tmp         = require('temporary');
 var tmp         = require('temporary');
 var Q           = require('q');
 var Q           = require('q');
 var fs          = require('fs');
 var fs          = require('fs');
@@ -57,7 +57,7 @@ var screenshotHandler = function() {
     this.openImage = function(imagePath) {
     this.openImage = function(imagePath) {
         var deferred = Q.defer();
         var deferred = Q.defer();
 
 
-        lwip.open(imagePath, function(err, image){
+        Jimp.read(imagePath, function(err, image){
             if (err) {
             if (err) {
                 debug('Could not open imagePath %s', imagePath);
                 debug('Could not open imagePath %s', imagePath);
                 debug(err);
                 debug(err);
@@ -76,7 +76,7 @@ var screenshotHandler = function() {
     this.resizeImage = function(image, newWidth) {
     this.resizeImage = function(image, newWidth) {
         var deferred = Q.defer();
         var deferred = Q.defer();
 
 
-        var currentWidth = image.width();
+        var currentWidth = image.bitmap.width;
         var ratio = newWidth / currentWidth;
         var ratio = newWidth / currentWidth;
 
 
         image.scale(ratio, function(err, image){
         image.scale(ratio, function(err, image){
@@ -101,7 +101,7 @@ var screenshotHandler = function() {
         var deferred = Q.defer();
         var deferred = Q.defer();
 
 
         // Create a canvas with the same dimensions as your image:
         // Create a canvas with the same dimensions as your image:
-        lwip.create(image.width(), image.height(), 'white', function(err, canvas){
+        new Jimp(image.bitmap.width, image.bitmap.height, 0xFFFFFF, function(err, canvas){
             if (err) {
             if (err) {
                 debug('Could not create a white canvas');
                 debug('Could not create a white canvas');
                 debug(err);
                 debug(err);
@@ -109,7 +109,7 @@ var screenshotHandler = function() {
                 deferred.reject(err);
                 deferred.reject(err);
             } else {
             } else {
                 // Paste original image on top of the canvas
                 // Paste original image on top of the canvas
-                canvas.paste(0, 0, image, function(err, image){
+                canvas.composite(image, 0, 0, function(err, image){
                     if (err) {
                     if (err) {
                         debug('Could not paste image on the white canvas');
                         debug('Could not paste image on the white canvas');
                         debug(err);
                         debug(err);
@@ -131,7 +131,7 @@ var screenshotHandler = function() {
     this.toBuffer = function(image) {
     this.toBuffer = function(image) {
         var deferred = Q.defer();
         var deferred = Q.defer();
 
 
-        image.toBuffer('jpg', {quality: 90}, function(err, buffer){
+        image.quality(90).getBuffer(Jimp.MIME_JPEG, function(err, buffer){
             if (err) {
             if (err) {
                 debug('Could not save image to buffer');
                 debug('Could not save image to buffer');
                 debug(err);
                 debug(err);
@@ -143,7 +143,7 @@ var screenshotHandler = function() {
             }
             }
         });
         });
 
 
-        return deferred.promise;        
+        return deferred.promise;
     };
     };
 
 
 
 
@@ -167,4 +167,4 @@ var screenshotHandler = function() {
     };
     };
 };
 };
 
 
-module.exports = new screenshotHandler();
+module.exports = new screenshotHandler();

+ 3 - 3
lib/tools/redownload/fileMinifier.js

@@ -296,7 +296,7 @@ var FileMinifier = function() {
         return deferred.promise;
         return deferred.promise;
     }
     }
 
 
-    // Avoid loosing time trying to compress some JS libraries known as already compressed
+    // Avoid losing time trying to compress some JS libraries known as already compressed
     function isKnownAsMinified(url) {
     function isKnownAsMinified(url) {
         var result = false;
         var result = false;
 
 
@@ -322,7 +322,7 @@ var FileMinifier = function() {
         return result;
         return result;
     }
     }
 
 
-    // Avoid loosing some trying to compress JS files if they alreay look minified
+    // Avoid losing some trying to compress JS files if they already look minified
     // by counting the number of lines compared to the total size.
     // by counting the number of lines compared to the total size.
     // Less than 2KB per line is suspicious
     // Less than 2KB per line is suspicious
     function looksAlreadyMinified(code) {
     function looksAlreadyMinified(code) {
@@ -351,4 +351,4 @@ var FileMinifier = function() {
     };
     };
 };
 };
 
 
-module.exports = new FileMinifier();
+module.exports = new FileMinifier();

+ 1 - 1
package.json

@@ -55,7 +55,7 @@
     "is-ttf": "0.2.2",
     "is-ttf": "0.2.2",
     "is-woff": "1.0.3",
     "is-woff": "1.0.3",
     "is-woff2": "1.0.0",
     "is-woff2": "1.0.0",
-    "lwip": "0.0.9",
+    "jimp": "0.2.28",
     "md5": "2.2.1",
     "md5": "2.2.1",
     "meow": "3.7.0",
     "meow": "3.7.0",
     "minimize": "2.1.0",
     "minimize": "2.1.0",

+ 16 - 16
test/api/screenshotHandlerTest.js

@@ -7,17 +7,17 @@ var path = require('path');
 describe('screenshotHandler', function() {
 describe('screenshotHandler', function() {
 
 
     var imagePath = path.join(__dirname, '../fixtures/logo-large.png');
     var imagePath = path.join(__dirname, '../fixtures/logo-large.png');
-    var screenshot, lwipImage;
+    var screenshot, jimpImage;
 
 
-    
-    it('should open an image and return an lwip object', function(done) {
+
+    it('should open an image and return an jimp object', function(done) {
         ScreenshotHandler.openImage(imagePath)
         ScreenshotHandler.openImage(imagePath)
             .then(function(image) {
             .then(function(image) {
-                lwipImage = image;
+                jimpImage = image;
 
 
-                lwipImage.should.be.an('object');
-                lwipImage.width().should.equal(620);
-                lwipImage.height().should.equal(104);
+                jimpImage.should.be.an('object');
+                jimpImage.bitmap.width.should.equal(620);
+                jimpImage.bitmap.height.should.equal(104);
 
 
                 done();
                 done();
             })
             })
@@ -26,14 +26,14 @@ describe('screenshotHandler', function() {
             });
             });
     });
     });
 
 
-    
-    it('should resize an lwip image', function(done) {
-        ScreenshotHandler.resizeImage(lwipImage, 310)
+
+    it('should resize an jimp image', function(done) {
+        ScreenshotHandler.resizeImage(jimpImage, 310)
             .then(function(image) {
             .then(function(image) {
-                lwipImage = image;
+                jimpImage = image;
 
 
-                lwipImage.width().should.equal(310);
-                lwipImage.height().should.equal(52);
+                jimpImage.bitmap.width.should.equal(310);
+                jimpImage.bitmap.height.should.equal(52);
 
 
                 done();
                 done();
             })
             })
@@ -43,8 +43,8 @@ describe('screenshotHandler', function() {
     });
     });
 
 
 
 
-    it('should transform a lwip image into a buffer', function(done) {
-        ScreenshotHandler.toBuffer(lwipImage)
+    it('should transform a jimp image into a buffer', function(done) {
+        ScreenshotHandler.toBuffer(jimpImage)
             .then(function(buffer) {
             .then(function(buffer) {
                 buffer.should.be.an.instanceof(Buffer);
                 buffer.should.be.an.instanceof(Buffer);
                 done();
                 done();
@@ -125,4 +125,4 @@ describe('screenshotHandler', function() {
                 done(err);
                 done(err);
             });
             });
     });
     });
-});
+});

+ 6 - 6
test/core/redownloadTest.js

@@ -228,14 +228,14 @@ describe('redownload', function() {
             newEntry.weightCheck.bodySize.should.equal(4193);
             newEntry.weightCheck.bodySize.should.equal(4193);
             newEntry.weightCheck.bodyBuffer.should.deep.equal(fileContent);
             newEntry.weightCheck.bodyBuffer.should.deep.equal(fileContent);
 
 
-            // Opening the image in lwip to check if the format is good
-            var lwip = require('lwip');
-            lwip.open(newEntry.weightCheck.bodyBuffer, 'png', function(err, image) {
-                image.width().should.equal(620);
-                image.height().should.equal(104);
+            // Opening the image in jimp to check if the format is good
+            var Jimp = require('jimp');
+            Jimp.read(newEntry.weightCheck.bodyBuffer, function(err, image) {
+                image.bitmap.width.should.equal(620);
+                image.bitmap.height.should.equal(104);
                 done(err);
                 done(err);
             });
             });
-            
+
         })
         })
 
 
         .fail(function(err) {
         .fail(function(err) {