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

Is it possible to resize images only when they exceed max-Size #1184

Closed
nevyen opened this issue Dec 7, 2015 · 6 comments
Closed

Is it possible to resize images only when they exceed max-Size #1184

nevyen opened this issue Dec 7, 2015 · 6 comments

Comments

@nevyen
Copy link

nevyen commented Dec 7, 2015

Hey,
maybe this question is too simple, but I don't get it.

Is it possible to resize images only when the exceed max-Size or max-height.

And how to resize them to a given width by keep the ratio ?

thanks
Dominic

@danialfarid
Copy link
Owner

It would always keep the ratio, so you can just set the width and the height will be calculated depending on centerCrop value.
For now the resize will be applied to all images. You can use Upload.imageDimension() and Upload.resize() services to apply your filtering before resizing.

@nevyen
Copy link
Author

nevyen commented Dec 7, 2015

Thanks for this hint I will try it. And many add a Wiki page

@nasir-awan
Copy link

I also have similar scenario, I want to scale down an image, if its larger than specific height or width. Once, we have resize it, we will upload it to server. How Upload.resize() works?

var resizedImage = Upload.resize(imagefile,100,100, 0.8,'image/jpg','1:2',true);

Upload.http({
url: test.com/url,
data: resizedImage ,
method: "PUT",
headers : {
'content-type': file.type
},
transformRequest: function(data, headersGetter) {
var headers = headersGetter();
delete headers.Authorization;
return data;
}
});

@danialfarid
Copy link
Owner

I updated the readme and added docs for Upload.resize()

@gmisiolek
Copy link

@danialfarid If I am not wrong, fixing this issue has only few lines of code :D

In resize.js I changed lines 41 - 46:

if (!width) {
  width = imageElement.width;
} else {
  if (width > imageElement.width) {
    width = imageElement.width;
  }
}
if (!height) {
  height = imageElement.height;
} else {
  if (height > imageElement.height) {
    height = imageElement.height;
  }
}

It works for me. What do you think?

@danialfarid
Copy link
Owner

Fixed at 11.0.0.
You can use ngf-resize-if

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