-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
Cropping consistency and Gravity. Allow changing aspect ratio of cropped images #1786
Cropping consistency and Gravity. Allow changing aspect ratio of cropped images #1786
Conversation
002b0b2
to
de416ad
Compare
8d8b553
to
074ff29
Compare
ec6d702
to
1fc1834
Compare
c412560
to
cdb5568
Compare
# | ||
def crop(size, crop_from = nil, crop_size = nil, upsample = false) | ||
def crop(size, render_size, crop_from = nil, crop_size = nil, render_crop = false, gravity = {}, upsample = false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method crop
has 7 arguments (exceeds 4 allowed). Consider refactoring.
# 2. If not, check if a default cropping mask is applied through definition settings size | ||
# 3. If requested size aspect ratio differs from the cropped area => Adjust cropping area first | ||
# | ||
def get_crop_area(size, render_size, crop_from, crop_size, render_crop, gravity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method get_crop_area
has 6 arguments (exceeds 4 allowed). Consider refactoring.
1ee2ca9
to
bafab27
Compare
bafab27
to
2ce3bb8
Compare
Thanks. And sorry for letting you wait so long. Unfortunately I am not sure I fully understand what this rather complex feature is meant for. I read the Google doc. Thanks for that. Am I assuming correctly that you want to use these values to align the image as I think this is overall a good idea, but the code is very(!) complex. Without tests and more example code (especially on the frontend) I am not able to review it. Could you provide more examples and tests? Thanks for your contribution |
7149328
to
8a38a6c
Compare
This probably needs a rebase now that we merged some of the extracted bug fixes. |
Rdy for review @tvdeyen |
@mickenorlen we switched the default branch to |
…gravity options Add render_gravity column to essence_picture. Add gravity selection to picture properties if specified in settings, also fix cropping for pictures using srcset
ba2cf0d
to
a5b68d7
Compare
@tvdeyen Force pushed a fresh single squash merge commit into main as rebase was a mess. |
I came up with a few small changes that might make this PR a bit easier for you to review. For example breaking out a new |
025d196
to
1c62f69
Compare
@tvdeyen, After refactoring most logic to |
1c62f69
to
4f67062
Compare
This pull request has not seen any activiy in a long time. |
This is still relevant and and useful feature that we would love to have, but this PR needs to be reworked from scratch since we made a lot of refactorings lately. |
Maybe this can be split up into smaller PRs? One that introduces the gravity feature and one that handles aspect ratio changes. |
I think this makes sense after we merged the support for active storage (#2288), because image_processing and lib vips have attention and other gravities build in. |
I've recently cleaned up the code behind this feature a bit as i used it in my own project. "The focus in this picture is: x: left/center/right, y: top/center/bot, zoom: in/closest/out" . Then the developer can make render choices based on this - cropping can be one of them, background-align another etc. In short i've made a class Render::Crop
def initialize(size:, original_size:, crop_from:, crop_size:, focus:, aspect_ratio: nil)
...
@crop_from = to_crop_from(crop_from) || { x: 0, y: 0 }
@crop_size = to_crop_size(crop_size) || @original_size
end
def adjust_crop_area_to_aspect_ratio
new_crop_size = case @focus[:zoom]
when :out, :closest
grow_crop_area
when :in
shrink_crop_area
end
crop_from = crop_from_after_crop_area_resize(new_crop_size)
[crop_from, new_crop_size]
end
...
private
# The wanted aspect ratio is taken either from size or a directly from aspect ratio
def wanted_aspect_ratio
@wanted_aspect_ratio ||= (@aspect_ratio.presence || aspect_ratio(@size))
end
end One thing that was useful for me to implement related to this feature was to make picture Can you give me your thoughts on all this and a quick explanation of how your recent refactorings influence this feature? |
I like the idea of a render/crop focus class. Could you elaborate what the values mean? Why is zoom in and zoom out a focus related value? I would rather think of a coordinate instead of a verb/command, but I probably miss some context. |
The focus zoom property is perhaps a bit unintuitive and I'm open for suggestions for another wording. In general
With With I've updated the comments in the In the |
This pull request has not seen any activiy in a long time. |
This pull request has not seen any activiy in a long time. |
Update 7/7
See comment: #1786 (comment)
What is this pull request for?
Closes #1783
Add consistency to cropping regardless if crop mask is applied or not or using srcset.
Render cropping. Allow changing aspect ratio of cropped images in render if
render_crop=true
- with addedgravity
settings (see screenshot doc for render cropping in action).Gravity. The gravity of an
essence_picture
can now be specified in content settings (1. for devs) image properties (2. for users - ifpresent?
in settings) or directly in render (3.). It can be read with proper priority, validation, fallbacks to defaults etc throughessence.gravity
method. Eg. if you want to use it for aligning background images or something other than its natural use in render_cropping.Screenshot doc with explanations and tests of render cropping in action
https://docs.google.com/document/d/1rRCEBYSnKczOS3HYNHFdy2s-EzY17B0G3ljp1vLMLis/edit?usp=sharing
TODO
Add
render_gravity
column to cms. I added the migration 20200701100718I have added tests to cover this change
I have followed Pull Request guidelines
I have added a detailed description into each commit message (Not so much but lots of comments in code)
1. Gravity in content settings
elements.yml
2. Gravity in page properties
I serialized the
render_gravity
(string in db) as JSON so its working as a hash. Then I had to split the params in three and combine them in controller:essence_pictures_controller.rb
3. Gravity in render