-
Notifications
You must be signed in to change notification settings - Fork 200
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
Question: Cropping to a relative portion of the image (in percents) #384
Comments
Good question, it would be like https://wsrv.nl/docs/crop.html#rectangle-crop but with percentages indeed. |
Thanks for your response! It does not necessarily mean to have equal parts, or that libvips needs to cut all all the parts in one go. The idea is just to request one part at a time, but instead of providing the absolute coordinates of the desired part, providing the relative part in percentages. When
But there are also use cases for none equal divisions / layouts for an image:
It doesnt seem to me this feature would have a big impact, because the existing If you point me to the right spot in the source, I'm willing to provide you with a PR and we can discuss this further in this PR. Kind regards, |
The only possible conflict with the current API spec would arise for
|
@kleisauke do you see value in adding this feature request? |
Sorry for the delay. I think this would be an interesting feature to add, but using a floating point API (i.e. values between Perhaps we should use the percent sign (
(And of course, we need to ensure that percentages with decimal places are also supported, such as I think this is relatively easy to add code-wise and could possibly be extended to the Let's mark this as an enhancement, I'll try to implement this sometime this week. |
Alright, great! Another possibility would be to use fraction notation. This would result in a higher precision then using floating points percentages (eg. 1/3 instead of 33.333%). This would also be closer to the actual use cases, where you are looking to divide the image in fractions. 100% would need to be expressed as ‘1/1’ to distinguish from an absolute dimension of 1px The same examples would be like:
|
Fraction notation is slightly more difficult to implement because the parser must guard against division by zero and NaN values. Commit e5489aa allows percentage-based values (denoted by a value ending with Documentation will be updated later to reflect this. |
Hi @kleisauke I have been using the relative cropping with success. Thanks a lot. As i understand correctly from #334 weserv is url_decoding the url parameter to allow for other query parameters inside this url of the raw image. My question to you: should weserv now also url_decode the c[w,h,x,y] parameters, since it now can contain special chars like |
Documentation has been updated. |
Say you want to crop an image to its upper left quadrant. The image should not be resized, only the top-left half of the image (1/4) should be retained. What is the best way to do this?
I understand it is an easy task if the image's dimensions are known beforehand. But what if you would like to skip the extra processing to assess the image's dimensions before cropping (and leave it up to wsrv)?
Is it possible to crop an image to a relative portion of the image, based on a percentage of the original size? Something like
cx=0&cy=0&cw=0.5&ch=0.5
? In the documentation it looks like you can only give absolute cropping values (in pixels) and would need to know the image dimensions beforehand.Alignment does support percentage values (or top-left portions), but this is only used when resizing the image and using
fit
orcover
and thus would always resize the image. If you would like to retain the image's ratio, this would always result in a resize without any cropping.Thanks for your help or suggestions.
The text was updated successfully, but these errors were encountered: