           .toBuffer (err, outputBuffer, info) ->
             if err
               return callback err
-            originalWidth = metadata.width
-            resizedWidth = info.width
-            factor = originalWidth / resizedWidth
+            if width
+              originalWidth = metadata.width
+              resizedWidth = info.width
+              factor = originalWidth / resizedWidth
+            else
+              originalHeight = metadata.height
+              resizedHeight = info.height
+              factor = originalHeight / resizedHeight
             out.buffer.send outputBuffer
             out.factor.send factor
             do callback


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

  c.inPorts.add 'buffer',
    datatype: 'object'

          .toBuffer (err, outputBuffer, info) ->
            if err
              return callback err
            if width
              originalWidth = metadata.width
              resizedWidth = info.width
              factor = originalWidth / resizedWidth
            else
              originalHeight = metadata.height
              resizedHeight = info.height
              factor = originalHeight / resizedHeight
            out.buffer.send outputBuffer
            out.factor.send factor
            do callback
