Image resize question


#1

The file module has an option to set the width and height, it states that it will not impact the file on the device however does it actually generate a file with that height / width?

Essentially our app sends images to the server for a photo gallery, however with cellphone images becoming larger and larger these files can be large. Now we can do image processing on the server however any amount of pre-processing we can do would be great. So the question is

When setting the image height and width via the file module, does this actually create an image with that height and width or is it more akin to just setting 'height=‘100’ via html?

Thanks.


#2

A new image is created with the given width / height.

I’d be very interested to hear some data points on the kind of size reduction you get via this approach!


#3

Just so I understand correctly, if I do a getImage like below and set the width and height the ‘file’ object returned will be the new image object?

  forge.file.getImage({ 
      source: "gallery", 
      saveLocation: "file", 
    width: 100, 
    height: 100 
}, function (file) { 
    forge.request.ajax({ 
        type: 'POST',
        url: 'http://my.server.com/upload/',
        files: [file],
        success: function(data) {
            // done
        }
    });
}); 

Thanks!


#4

Yup :slight_smile:

Specifically, on iOS we create a new, empty UIImage object and then transform and blit the original image into it.

On Android we create a new Bitmap from the original and apply a transformation matrix to it.

In both cases the process happens in-memory and returns the resultant binary image data directly to forge.request so it’s not cluttering the disk or gallery with extra files.


#5

Is the same true if you base64 the image as well? I have noticed on android, this seems to be the case but on ios it is the full size when sending it up to the server


#6

base64 unfortunately follows a completely different code-path, it was never designed for big files or images for that matter.