     datatype: 'integer'
     description: 'New height'
     required: false
-  c.outPorts.add 'canvas',
-    datatype: 'string'
+
+  c.outPorts.add 'out',
+    datatype: 'all'
+    description: 'Resized buffer'
+  c.outPorts.add 'factor',
+    datatype: 'number'
+    description: 'Original over resized dimensions factor'
+    required: false
   c.outPorts.add 'error',
     datatype: 'object'
     required: false
 
   noflo.helpers.WirePattern c,
-    in: ['path']
+    in: ['in']
     params: ['width', 'height']
-    out: ['canvas']
+    out: ['out', 'factor']
     async: true
     forwardGroups: true
   , (payload, groups, out, callback) ->
+    if (not Buffer.isBuffer payload) and (typeof payload isnt 'string')
+      return callback Error 'Input is not a valid buffer nor image path'
     width = c.params.width
     height = c.params.height
     if not width? and not height?
       width = 256
-    path = payload
     try
-      inputBuffer = sharp path
+      inputBuffer = sharp payload
       inputBuffer.metadata (err, metadata) ->
         if err
           return callback err
-        inputBuffer
-        .resize width, height
-        .withMetadata()
-        .withoutEnlargement()
-        .toFormat 'png'
-        .toBuffer (err, outputBuffer, info) ->
-          if err
-            return callback err
-          # Create image with buffer as src
-          image = new Canvas.Image
-          image.src = outputBuffer
-          # Create a host canvas and draw on it
-          canvas = new Canvas(info.width, info.height)
-          ctx = canvas.getContext '2d'
-          ctx.drawImage image, 0, 0, info.width, info.height
-          canvas.originalWidth = metadata.width
-          canvas.originalHeight = metadata.height
-          out.send canvas
-          do callback
+        # Try to preserve the same format, if there's EXIF
+        if metadata.exif?
+          inputBuffer
+          .resize width, height
+          .withMetadata()
+          .withoutEnlargement()
+          .toBuffer (err, outputBuffer, info) ->
+            if err
+              return callback err
+            originalWidth = metadata.width
+            resizedWidth = info.width
+            factor = originalWidth / resizedWidth
+            out.out.send outputBuffer
+            out.factor.send factor
+            do callback
+        else
+          inputBuffer
+          .resize width, height
+          .withMetadata()
+          .withoutEnlargement()
+          .toFormat 'png'
+          .toBuffer (err, outputBuffer, info) ->
+            if err
+              return callback err
+            originalWidth = metadata.width
+            resizedWidth = info.width
+            factor = originalWidth / resizedWidth
+            out.out.send outputBuffer
+            out.factor.send factor
+            do callback
     catch err
       return callback err
 

  c = new noflo.Component

  c.icon = 'expand'
  c.description = 'Resize a given image to the new dimension'

  c.inPorts.add 'path',
    datatype: 'string'
    description: 'Path to image to be resized'
  c.inPorts.add 'width',
    datatype: 'integer'
    description: 'New width'

noflo = require 'noflo'
sharp = require 'sharp'
path = require 'path'

# @runtime noflo-nodejs
# @name Resize
