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

resize & crop to fit the exact resolution #93

Open
nchieffo opened this issue Sep 16, 2013 · 4 comments
Open

resize & crop to fit the exact resolution #93

nchieffo opened this issue Sep 16, 2013 · 4 comments

Comments

@nchieffo
Copy link

Hello, my name is Nicolò and I would like to succest a new feature, about resizing an image.

I work for a web company that develops web sites and portals. Currently one of our biggest problem is image handling: customers do not want to resize images to create thumbnails.
They just want to attach a big image, and the thumbnail must be created automatically.

Your library works well for this purpose, but does not completely cover all scenarios:

  1. very frequently, the thumbnail must have a different aspect ratio than the bigger image, because the web agency that produces the website graphic mockups made this choice (square thumbnails and rectangular big images)
  2. very frequently, customer do not want to cope with image resolution, because they don't have resize tools, so even for bigger images that just want to upload a file and they expect that the result is an image that looks well in the targeted website area, even if the file resolution is different from the one required.

Of course in both scenarios stretching the image is not a good idea, and resizing the whole image keeping the image aspect ratio is impossible, due to the strict graphic mockup requiremets.

I would propose a new Resize & Crop combined mode that can be called FIT_EXACT_WITH_CROP.

Scalr.resize(image, Scalr.Method.SPEED, Scalr.Mode.FIT_EXACT_WITH_CROP, 150, 100);

This mode fits the requirement of having a thumbnail of the exact resolution (150x100) without losing image proportion.
The algorythm should extract the best rectangular area of the desired aspect ratio, by cropping and resizing the input image.

say you have an image of 1500x500, the algorithm should extract a thumbnail of 150x100 in the following steps:

  1. crop the image to have an aspect ration of 3:2 (150x100)
  2. resize the image to be 150x100

more sub algorithms can be created to specify the anchor point.
Scalr.Mode.FIX_EXACT_WITH_CROP _ANCHOR_TOP_LEFT
Scalr.Mode.FIX_EXACT_WITH_CROP _ANCHOR_TOP
Scalr.Mode.FIX_EXACT_WITH_CROP _ANCHOR_TOP_RIGHT
....

What do you think? Let me know if you are interested in this feature.
Thanks

@jinahya
Copy link

jinahya commented Feb 10, 2015

I'm working on a little project that seems support your requirements. Please take a look at jinahya-imgscalr-lib and javadoc. You can run the unit tests (in the develop branch) and check the output images. My method has magnification factor, horizontal weight, and vertical weight for controlling the size and how to relocate the resized image in the target area.

@wimdeblauwe
Copy link

+1 for this. It seems to exist already in the PHP world: http://image.intervention.io/api/fit I need the same thing for Java.

@aldidisha
Copy link

This is very helpful for thumbnails in different ratio, and would be nice to be included in library, im doing the above calculations manually in one of my projects, finding the highest possible rectangle that would satisfy the ratio i want than i crop it and than resize to desired size. (Highest possible rectangle will allow me to crop to desired ratio without loosing much content of original photo)

@vguna
Copy link

vguna commented Feb 28, 2016

Looks like this would fit your requirements?

#77

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

5 participants