bergben / ng2-img-max

Angular 2 module to resize images down to a certain width and height or to reduce the quality to fit a certain maximal filesize - all in the browser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to resize image with both max-width: X, or max-height: X while keeping the aspect ratio (and leaving the other larger)

dvirHam opened this issue · comments

If I could use the imageExifService it was easy but since it's private I don't figure out how to do this.
Can I do this without overriding it?

From the documentation I think the following should work, haven't tried it myself yet:
Method to resize files if necessary down to a certain maximal width or maximal height in px. If you want only one limit just set the other max to 10.000: for example resize([myfile1,myfile2],2000,10000).subscribe([...]

Having said that, since this library already uses EXIF it would be great to expose the properties using a service.
I can open a separate issue if needed.
I, for example, need to get the geo location of the image if it exists and resize it before uploading. If I could get it in the same package it would be great.

I'm using the resizeImage function with Angular7 to resize a photo taken with a Smartphone.
I noticed that if we fix the width value but the orientation of the pictures produce a rotation then the values maxWidth/maxHeight must be inverted because of that rotation and currently this inversion is not taken into account.
I extracted the private function and inserted the following example logic:

let currentWidth = orientedImg.width;
let currentHeight = orientedImg.height;

// If Landscape, invert resize values to respect the EXIF orientation
if (currentWidth > currentHeight) {
    let temp = maxWidth;
    maxWidth = maxHeight;
    maxHeight = temp;
}

Now the image respect w/h sizes accordingly with the original EXIF orientantion!

I have implemented the relevant service here if anyone is interested since there was no response here:
https://github.com/IsraelHikingMap/Site/blob/master/IsraelHiking.Web/sources/application/services/image-resize.service.ts