Skip to content
This repository has been archived by the owner on Jun 11, 2021. It is now read-only.

Calculation of width OR height based on original image #4

Closed
maku opened this issue Oct 31, 2017 · 2 comments
Closed

Calculation of width OR height based on original image #4

maku opened this issue Oct 31, 2017 · 2 comments

Comments

@maku
Copy link

maku commented Oct 31, 2017

For the resize method it would be great if you are able to provide only one value (newWidth OR newHeight) and the other value is calculated based on the ratio of the orignal image.

@bartholomej
Copy link
Contributor

bartholomej commented Nov 8, 2017

@maku You might be interested in this older fork: https://github.com/bartholomej/ng2-pica/commits/aspect-ratio

Usage
When keepAspectRatio is true then width + height parameters
become maxWidth + maxHeight parameters

Just add true as 4th parameter. It is optional and default value is false => without breaking changes.

let newWidth = 2048;
let newHeight = 2048;
let keepAspectRatio = true;

this.ng2PicaService.resize([someFile], newWidth, newHeight, keepAspectRatio).subscribe((result)=>{
  //all good, result is a file
  console.info(result);
}, error =>{
  //something went wrong 
  console.error(error);
});

If you wanna try it right now, you can install it like this (temporary solution):
Just add to your package.json
"ng2-pica": "git+https://github.com/bartholomej/ng2-pica.git#keep-aspect-ratio"

But I'll make a PR ;)
I made PR: #7

@bergben
Copy link
Owner

bergben commented Nov 8, 2017

Thanks for reporting this issue @maku , it is fixed in 1.2.0 and a even bigger thanks to @bartholomej for the PR, great work!

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

No branches or pull requests

3 participants