I have a Parse Server
where I upload UIImageJPEGRepresentation
(bytes array I think it's called) and send it to my nodejs server.
What I want is to get the width
and height
from that bytes array.
I'm using the parse-image
module, but there are times that the width and height are fetched in reverse, meaning the width is the actual height and the height is the actual width!
Here's the function I'm calling inside an afterSave trigger:
var storeImageDimensions = function(postObject) {
var imageFile = postObject.get("imageLowQuality");
Parse.Cloud.httpRequest({
url: imageFile.url(),
success: function(response) {
// The file contents are in response.buffer.
var Image = require("parse-image");
var image = new Image();
// ----------------------------------
image.setData(response.buffer, {
success: function() {
var imageDimensions = {};
imageDimensions.width = image.width();
imageDimensions.height = image.height();
// ----------------------------------
postObject.set("imageDimensions", imageDimensions);
postObject.save(null, {useMasterKey: true});
},
error: function(error) {
// The image data was invalid.
}
})
},
error: function(error) {
// The networking request failed.
}
});
}
Any idea why's that happening? Also, do you suggest any other modules that can take that kind of input?