Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dvirHam opened this issue Feb 7, 2018 · 3 comments

Comments

@dvirHam
Copy link

dvirHam commented Feb 7, 2018

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?

@dvirHam dvirHam changed the title How to get image with max-width: X, or max-height: X while keeping the aspect ratio How to get image with both max-width: X, or max-height: X while keeping the aspect ratio Feb 7, 2018
@dvirHam dvirHam changed the title How to get image with both max-width: X, or max-height: X while keeping the aspect ratio How to resize image with both max-width: X, or max-height: X while keeping the aspect ratio (and leaving the other larger) Feb 7, 2018
@HarelM
Copy link

HarelM commented Jun 22, 2018

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.

@davideas
Copy link

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!

@HarelM
Copy link

HarelM commented Feb 27, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants