// Dependencies
var path = require('path'),
  fs = require('fs'),
  gm = require('gm'),
  uuid = require('node-uuid'),
  mongoose = require('mongoose'),
  model = mongoose.model('ImageMetaData'),
  response = require('./responseHelpers'),
  addToDb = require('./mongoosehelpers').addToDb,
  client = require('./knoxHelpers').awsClient(),
  imagePath = '/tmp/';

module.exports = {
  // Upload requested image to to s3 bucket
  // TODO: mention public read in README 
  upload: function(req, res, key) {
    var data = '',
      readStream = fs.createReadStream(imagePath + key + '.jpg');

    readStream.on('data', function(chunk) {
      data += chunk;
    });

    readStream.on('close', function() {
      var req = client.put('/' + key, {
        'Content-Length': data.length,
        'Content-Type': 'image/jpeg',
        'x-amz-acl': 'public-read'
      });

      req.on('response', function(resp) {
        if (resp.statusCode === 200) {
          addToDb(req, res, key);
          response.getRes(req, res, key);
        } else {
          errRes(req, res, 500);
        }
      });

      req.end(data);
    });
  },

  //TODO: move to seperate file
  // Obtain the dimensions of the requested image
  getDimensions: function(req, res) {
    gm(imagePath + req.key + '.jpg')
    .size(function (err, size) {
      if (err) {
        console.error('Image transformation failed with error:', err);
        throw err;
      }

      response.metaData(req, res, req.key, size.width, size.height, 200);
    });
  }
};


@@ -17,180 +17,55 @@
 var 
-path = require('path'),%0A  fs = require('fs'),%0A  gm = require('gm'),%0A  uuid = require('node-uuid'),%0A  mongoose = require('mongoose'),%0A  model = mongoose.model('ImageMetaData
+fs = require('fs'),%0A  im = require('imagemagick
 '),%0A
@@ -1125,10 +1125,19 @@
     
-gm
+im.identify
 (ima
@@ -1165,28 +1165,18 @@
 jpg'
-)%0A    .size(
+, 
 function
  (er
@@ -1175,19 +1175,22 @@
 tion
- 
 (err, 
-size
+features
 ) %7B%0A
@@ -1352,39 +1352,24 @@
 ey, 
-size.width, size.height
+features
 , 200);%0A
     
@@ -1360,24 +1360,25 @@
 ures, 200);%0A
+%0A
     %7D);%0A  %7D%0A

send more image data to response helper