0

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?

Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Sotiris Kaniras
  • 520
  • 1
  • 12
  • 30
  • u may need to consider EXIF as well as your UIimage .... https://stackoverflow.com/questions/15239719/convert-uiimage-to-nsdata-without-using-uiimagepngrepresentation-or-uiimagejpegr you may be missing meta-data on 'rotation' contain in EXIF – Robert Rowntree May 13 '18 at 11:46
  • @RobertRowntree If that's the case, shouldn't it always happen? – Sotiris Kaniras May 13 '18 at 14:50
  • 1 - 4 would not flip H, W per your issue... 5 - 8 flip H, W details : https://stackoverflow.com/questions/20600800/js-client-side-exif-orientation-rotate-and-mirror-jpeg-images/20600801#20600801 – Robert Rowntree May 13 '18 at 16:20

0 Answers0