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

Add flag to blowUp or not #91

Open
robertoschwald opened this issue Apr 30, 2013 · 5 comments
Open

Add flag to blowUp or not #91

robertoschwald opened this issue Apr 30, 2013 · 5 comments

Comments

@robertoschwald
Copy link

Currently, Scalr always blows up (scales-up) images which are too small for the given max-width/height.

It would be great if there is a possiblity to set a non-blowup Mode, so too small images will not be scaled up.

@ghost
Copy link

ghost commented Apr 30, 2013

Robert, can you clarify the behavior a bit more -- I don't quite understand.

For example, the current behavior: If you have a 100x100 image and pass in a max width/height of say 500, imgscalr will "blow up" or resize the image to 500x500.

Given that example (or maybe a different one you had in mind) what kind of behavior did you want imgscalr to have?

@robertoschwald
Copy link
Author

Currently, if I don't want small images to be scaled up, I need to compute the scale factor outside of Scalr to decide if I need to rescale or not. It would be great if I can set a mode in Scalr, which only resizes if the image is too big for maxWidth or maxHeight and otherwise does not scale. This is what I call blowUp (true/false) in my former scaling method.

@ghost
Copy link

ghost commented Apr 30, 2013

Robert, can you paste the code for your current impl here so I can see exactly what you are asking for?

It sounds like you want a mode where imgscalr honors a primary dimension (same as Scalr.Mode now) exactly instead of the current targetWidth and targetHeight, you want to provide maxWidth and maxHeight dimensions, and if the image is already within those dimensions, then do nothing -- is that right?

@robertoschwald
Copy link
Author

Here is the code I use to decide if I need to scale or not. If image is too small, scalr is not called (so no blowUp happens). blowUp is a boolean in my method signature.

    ...
    // calculate if vertical or horizontal scaling is required
    float imageWidth = rgbImage.getWidth();
    float imageHeight = rgbImage.getHeight();
    float verticalScale = maxHeight / imageHeight;
    float horizontalScale = maxWidth / imageWidth;
    float scale = verticalScale;
    if (horizontalScale < verticalScale) scale = horizontalScale;
    if (!blowUp && scale > 1) scale = 1;
    if (scale != 1){
      // Resize
      rgbImage = Scalr.resize(rgbImage, Scalr.Method.QUALITY, Scalr.Mode.AUTOMATIC, maxWidth, maxHeight);
    }
    ...

@ghost
Copy link

ghost commented Apr 30, 2013

Thanks Robert!

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

No branches or pull requests

1 participant