Allow arbitrary gravity shifts when cropping#205
Conversation
|
Hello Marcin, thank you very much for your work on this enhancement. I understand the need for additional north-east, south-east, south-west and north-west gravities. This would bring things line with *magick's Are you able to provide some functional tests to help me understand what the slightly more complex variable (0.0 - 1.0) crop gravity might provide beyond the existing extract feature? |
|
I think the gravity feature does not provide new feature beyond extract in general. You can always first extract area with desired aspect ratio, then scale. With gravity you do not have to check the size of the photo first. For this reason adding noth-east, etc. would be valuable, because it does not require a priori knowledge of aspect ratio. |
|
Thanks for providing more info about "variable gravity" @ndziorlg. Your scenario is similar to #130 and your addition would seem to make more sense as an improvement to the |
|
@ndziorlg Sorry for the delay getting back to this PR and thanks again for your contributions. Are you able to separate the features in your excellent work and, at least initially, include only the addition of new The next release is taking shape on the This should keep separate and therefore allow any deliberation on adding the % to crop vs extract (vs crop+extract) to continue unabated. |
|
👍 |
|
Hi @martinheidegger, thanks for the +1. Are you able to provide more details of which feature(s) you're referring to as there are a couple of improvements under discussion here? |
|
@lovell Just read the code and really liked what I saw. Having the same properties as GraphicsMagick is a good step ahead. Since |
|
@martinheidegger Thank you! |
|
I'm still very happy to accept a PR that adds support for north-west etc. gravities part of this PR. Our golang sibling has just added this via DAddYE/vips@6e59422 The addition of #236 should provide enough API for the variable cropping/extracting feature. |
|
Might take a look at pulling in the additional gravities soon if there still isn't movement here. |
|
I briefly looked at using the approach laid out here but it wasn't passing unit tests. In favor of time, I simply extended the existing approach to support these extra gravity settings in pull request #291. |
|
#291 has been merged, adding support for the additional gravity values, thanks @brandonaaron. |
|
v0.11.4 is now available via npm and includes the additional corner gravities part of this PR. The variable gravity idea should be made possible via #236 - please feel free to continue the discussion there. Thanks again for your time and suggestions @ndziorlg! |


In an CMS type application I develop I need to determine the gravity for the image for many different crop sizes.
For example, the person's head in the photography should always be visible and the thumbnail on the main page is different then the thumbnail in the list of articles. If it is placed in the upper left corner then I would have to choose gravity "north" or "west" dependent on the aspect ratio. This is the reason why set of "centre", "north", "east", etc. is not enough.
Additionally, I am trying to add visual tool to the editor to choose the most important part of the photo (always visible), with a single click. For this purpose I need to set arbitrary value for the gravity, e.g. in units of 0-100% in horizontal and vertical dimension.