-
Notifications
You must be signed in to change notification settings - Fork 139
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
Wish: Add support for focal point #602
Comments
We call it "gravity" in the JSON API.
https://github.com/imazen/imageflow/blob/main/docs/src/json/constrain.md
I haven't implemented in the URL API yet, because I'm wondering if we want
to support multiple focal points or a rectangle instead of just a point
…On Sun, May 22, 2022, 1:49 PM Holger Rasch ***@***.***> wrote:
Hello and thanks for your efforts in this great library. Today i
researched on some points in case of responsive images. One interesting
feature for a resizing library would be the option to define a focal point.
If an image gets resized, this point ensures that the "important" part of a
picture is still included. I know there's an option "anchor" that goes in
this direction, but support for a focal point would be much better. Here's
some info from another Software that supports such an option:
https://docs.imgix.com/tutorials/focal-point-cropping
Thanks.
—
Reply to this email directly, view it on GitHub
<#602>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAA2LH75MUWQ75X45K6TWEDVLKFUJANCNFSM5WT2ZQ6A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
My opinion: Support one point and an optional second point. Two points are the easiest way to span a rectangle if needed ;-) |
If automatic crop is also specified in a command query, should padding be used to absolutely prevent cropping into the focus rectangle if too large? What do you think is most intuitive? |
I guess it would be more intuitive not to use padding and just crop the focus-area. The focus area is to mark the most important area of the picture. Maybe it‘s possible to „zoom out“ so the focal area keeps untouched while the requested ratio is still valid? |
Well, the problem is that zooming out would add padding if the image isn't large enough, right? Ex, if you focused the whole image, then requested any different aspect ratio, there'd be nothing to show. |
I would expect to use the center of the focal area as reference and crop, even if this violates the focal area. |
If so, then there's no reason for a 2nd focal point, right? Because it would be no different than simply providing the center of the desired rectangle? |
Yes, finally it would result in the same behavior. The difference would be that if you change the ratio, the focal area would be the center instead of the center of the image. To be honest, I currently solved this issue by using the object-fit together with object-position and css custom-properties. This finally result in larger images than necessary to be transfered. The typical use-case is that you have e.g. a ratio of 16:9 on desktop-size and a ratio of 4:3 on mobile phones. If the focus is not in the center of the image, the important part moves out of screen. If you define a focal area my expected behavior ( if the native resolution is e.g. 1600x1200, focal-area 200:200, 600:600) is that on desktop, where you need a width of 1600px and height of 900px, the center of this area is calculated (400:400), then the required image-area is calculated (0:-50, 1600:850), the area is moved to the origin (0:0, 1600:900). On mobile, where you need a ratio of 4:3, (width: 640px, height: 480px), the area would be 80;160, 720;640. If you have a ratio of 4:3 with a width: 320px, height: 240px, the result would be the area of 240:280, 560:520, what is cropping the focal area unnecessary. In this case the image should be resized to show the complete focal area (172:200, 628:600). Your edge-case, where the focal area is very large and you can‘t resize without exceeding the native image size, the image should be resized to the max and then cropped. Hope my explaination is not too confusing 🥴 |
There are cases where users want cropping to be prevented, like #594. We also probably want to offer integration with other features, like face detection: imazen/imageflow-dotnet#44 |
I think, you select mode „crop“ to have an image, covering the image area. Adding padding suddenly will lead to more unexpected results than cropping the image if zooming out is not possible anymore because it exceeds the image size. |
Hi @lilith Even though I'm a developer I actually end up using the resizer as an end user a lot. And I'm always surprised as how difficult certain simple looking scenarios end up being, so I'll try to summarize why one point is ok, but not enough... Note that I like the https://docs.imgix.com/tutorials/focal-point-cropping explanations, because it does cover a lot of aspects. But again, not quite all. In my world, here's what usually should happen:
For simplicity, let's assume we have these predefined formats
Part 1: Point or Area depends on Min/Max controlNow IMHO the user should just say what must certainly be in the image, so that automatic cropping (almost) never takes too much away. With this, I think the designer should be able to specify rules which try to
For example, a SQUARE image MINIMUM would still result in something like this: Whereas SQUARE MAXIMUM would result in something like this: The imgix tries to solve this using the zoom factor, but that only works if the user is optimizing the image for exactly one specific use case (so it's a great idea, but often wouldn't be enough). So to summarize part 1
Part 2: More extremesFor wide banners the previous example would fail quickly. So there is either... ...A need for multiple priority areas where the user can determine different priority areas depending on the extremes (this should probably be handled at the CMS level, but could also be handled at the resizer level which would then result in a banner like I believe that Part 1 would best be solved at resizer level. Part 2 is probably more diverse in what can be necessary, so for now I think we shouldn't handle it yet, until it's really clear what the requirements are. |
@HRasch Basically what you're describing is certainly correct. If the resulting bounds would be outside of the possible image, the system should automatically do "the right thing". |
Any progress on this? @lilith |
@lilith any updates on this ? |
bump? |
Wow, this was a great read. I've been hoping for this kind of feature+functionality for a long time, but was unaware of these discussions over here on ImageFlow. We recently worked through a few real-world (CMS) edge cases. I am probably repeating stuff above and in #594, but the main pain points are a) having to know the image's width and height (file access is slow, handling many image formats is "dependencies"), and b) maths, which slow me down. Here is the demo we built and the two main approaches we needed, Target() and Focus(). It always helps to solve a real-world example and not cover "every hypothetical edge case." These covered the majority of our experience-based use cases (we are a website building agency AND present solutions that our users (CMS editors) could understand and use (sometimes with a little trial and error)). Rather than explain, see the linked example below. The two different methods both work on X,Y that are decimal percentages, but Target() can zoom, Focus() will not. I thought I was covering 99% of use-cases, but after reading these two ImageFlow issues, I see I am more in the 96% range. ;) Anyhow, after working this through we did put a version of the Focus() solution on 2 production sites and it is working very well. The performance ding is minimized because we are only doing it for 1 image on the page and the client was both impressed and happy with the result. I hope this gets worked on soon and that there is some way I can help. I don't know if this helps beyond, "show your work" - but in working through this the two key items that made both the think-through and (C#) code reasonable were
|
Hmm, so here's my current thought: &c=x1,y1,x2,y2 as new percentage based crop syntax, nobody seems to use pixels. All coordinates hereafter are % If &mode=crop: &c.preserve=x1,y1,x2,y1,x1,y1,x2,y2, etc, allowing multiple rectangles to preserve with decreasing priority. A single point is also permitted, which behaves the same as 'gravity' &c.gravity=x1,y1 &c.fit= I'd love to have help building out a table with these interactions and definining what will make the most sense to people, and which crop fit modes we can omit. |
https://docs.imageflow.io/querystring/transforms.html for query command ref The json api has more extensive fit modes: https://docs.imageflow.io/json/constrain.html &c.gravity might need to just be &gravity so it can be used for padding. ®ion could exist to add padding/canvas by allowing < 0 and > 1 values, and replace &c... thoughts? |
For percentages, should range be 0..100 or 0..1? What seems easiest? Should &c exist separately from ®ion ? |
For ours, I felt most comfortable with 0 .. 100 and optionally allowing up to 2 decimal places. This is because we felt most comfortable communicating this to clients as a percentage. But since you said "easiest," industry standards have muddied those waters a bit, at least if you do CSS a lot. :) So I am just stating my preference: 0.00 .. 100.00. I can easily predict that some people will want 4 or more decimal places though. |
Also, in case you didn't notice, the url params exist for |
It's mostly that I don't want |
I've sketched out my idea of the interactions and details - can you all request access and leave comments/edits? This is certainly complex to handle in a way that interacts well with all other features. https://docs.google.com/spreadsheets/d/1RDWcTka6MfMXsd5tJES4O7UYFLn4sKw7EgFj9Hd97hc/edit?usp=sharing |
Hello and thanks for your efforts in this great library. Today i researched on some points in case of responsive images. One interesting feature for a resizing library would be the option to define a focal point. If an image gets resized, this point ensures that the "important" part of a picture is still included. I know there's an option "anchor" that goes in this direction, but support for a focal point would be much better. Here's some info from another Software that supports such an option:
https://docs.imgix.com/tutorials/focal-point-cropping
Thanks.
The text was updated successfully, but these errors were encountered: