sharp package update / check is sharp is available
sharp package update / check is sharp is available

--- a/onvif/snapshot.js
+++ b/onvif/snapshot.js
@@ -1,7 +1,12 @@
 module.exports = (RED) => {
     "use strict";
     let onvif = require("node-onvif");
-    const sharp = require('sharp');
+    let isSharpAvailable = false;
+    try {
+        const sharp = require('sharp');
+        isSharpAvailable = true;
+    }
+    catch (ex) {}
 
     function snapshot(config) {
         RED.nodes.createNode(this, config);
@@ -43,7 +48,7 @@
         }).then((res) => {
             let prefix = 'data:' + res.headers['content-type'] + ';base64,';
 
-            if (config.resize) {
+            if (config.resize && isSharpAvailable) {
                 sharp(Buffer.from(res.body, 'binary'))
                     .resize(config.resize)
                     .toFormat('png')

--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
     "name": "node-red-contrib-onvif",
-    "version": "1.0.1",
+    "version": "1.0.2",
     "description": "A Node-RED node that interacts with ip cameras using the ONVIF protocol",
     "repository": {
         "type": "git",
@@ -8,7 +8,7 @@
     },
     "dependencies": {
         "node-onvif": "^0.1.7",
-        "sharp": "^0.26.2"
+        "sharp": "^0.28.3"
     },
     "inputs": 1,
     "keywords": [

comments