Browse Source

replace graphicsmagick with sharp

Pascal Temel 5 years ago
parent
commit
05c17f2dc9
3 changed files with 20 additions and 12 deletions
  1. 1 2
      config.sample.js
  2. 17 9
      controllers/utilsController.js
  3. 2 1
      package.json

+ 1 - 2
config.sample.js

@@ -79,8 +79,7 @@ module.exports = {
 
 		/*
 			NOTE: Thumbnails are only for the admin panel and they require you
-			to install a separate binary called graphicsmagick (http://www.graphicsmagick.org)
-			for images and ffmpeg (https://ffmpeg.org/) for video files
+			to install a separate binary called ffmpeg (https://ffmpeg.org/) for video files
 		*/
 		generateThumbnails: false,
 

+ 17 - 9
controllers/utilsController.js

@@ -47,17 +47,25 @@ utilsController.generateThumbs = function(file, basedomain) {
 					})
 					.on('error', error => console.log('Error - ', error.message));
 			} else {
-				let size = {
+				let resizeOptions = {
 					width: 200,
-					height: 200
+					height: 200,
+					fit: 'contain',
+					background: {
+						r: 0,
+						g: 0,
+						b: 0,
+						alpha: 0
+					}
 				};
-				gm(path.join(__dirname, '..', config.uploads.folder, file.name))
-					.resize(size.width, size.height + '>')
-					.gravity('Center')
-					.extent(size.width, size.height)
-					.background('transparent')
-					.write(thumbname, error => {
-						if (error) console.log('Error - ', error);
+
+				sharp(path.join(__dirname, '..', config.uploads.folder, file.name))
+					.resize(resizeOptions)
+					.toFile(thumbname)
+					.catch((error) => {
+						if (error) {
+							console.log('Error - ', error);
+						}
 					});
 			}
 		}

+ 2 - 1
package.json

@@ -21,12 +21,13 @@
     "express-handlebars": "^3.0.0",
     "express-rate-limit": "^2.11.0",
     "fluent-ffmpeg": "^2.1.2",
-    "gm": "^1.23.1",
     "helmet": "^3.11.0",
     "jszip": "^3.1.5",
     "knex": "^0.14.4",
     "multer": "^1.3.0",
+    "npm": "^6.4.1",
     "randomstring": "^1.1.5",
+    "sharp": "^0.21.0",
     "sqlite3": "^3.1.13"
   },
   "devDependencies": {