Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/imager.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ var gm = require('gm').subClass({ imageMagick: true })
, knox = require('knox')
, async = require('async')
, os = require('os')
, _ = require('lodash');
, _ = require('lodash')
, mmm = require('mmmagic')
, Magic = mmm.Magic;

var magic = new Magic(mmm.MAGIC_MIME_TYPE);

var debug, config, storage, uploadedFiles = [];
var tempDir = path.normalize(os.tmpDir() + path.sep);
Expand All @@ -26,6 +30,7 @@ var contentType = {
'image/png': '.png',
'image/gif': '.gif'
};
var mimeTypes = Object.keys(contentType);

/**
* Initialize Imager with config
Expand Down Expand Up @@ -835,8 +840,21 @@ function getFileInfo (file, cb) {
name: typeof(file) == 'string' ? file.split('/')[file.split('/').length - 1] : file.name,
path: typeof(file) == 'string' ? file : file.path
};
file = f;
cb(null, file);

if (mimeTypes.indexOf(f.type) < 0) {
magic.detectFile(file, function(err, result) {
if (err) throw err;
if (mimeTypes.indexOf(result) < 0) {
throw new Error('Uploaded file is not a supported image');
}
f.type = result;
file = f;
cb(null, file);
});
} else {
file = f;
cb(null, file);
}
};

function getFileType(file) {
Expand Down
21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
"name": "imager",
"description": "Easy way to resize, crop and upload images to Rackspace cloudfiles and Amazon S3",
"version": "0.2.6",
"keywords": ["upload", "image", "graphicsmagick", "imagemagick", "rackspace", "cloudfiles", "resize", "file", "crop", "amazon", "s3"],
"keywords": [
"upload",
"image",
"graphicsmagick",
"imagemagick",
"rackspace",
"cloudfiles",
"resize",
"file",
"crop",
"amazon",
"s3"
],
"homepage": "https://github.com/madhums/node-imager",
"repository": {
"type": "git",
Expand All @@ -14,12 +26,13 @@
"node": ">= 0.8.x"
},
"dependencies": {
"async": "0.2.x",
"gm": "1.13.x",
"pkgcloud": "0.8.x",
"knox": "0.8.x",
"lodash": "2.4.1",
"mime": "1.2.x",
"async": "0.2.x",
"lodash": "2.4.1"
"mmmagic": "^0.3.8",
"pkgcloud": "0.8.x"
},
"devDependencies": {
"mocha": "1.14.x",
Expand Down