-
Notifications
You must be signed in to change notification settings - Fork 77
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
Add resize_to_cover #120
Add resize_to_cover #120
Conversation
It seems to be related to assumptions around method names. Pretty tricky :D
My method requires knowing the dimensions of the image, so it needs to be loaded. Changing the method name so that it doesn't start with I see this PR too, that seems slightly related: https://github.com/janko/image_processing/pull/75/files |
I've gone with renaming the method to If you're happy, I think this one is ready to go. |
Hi @janko, just wondering if you needed me to do anything else to this PR? I'm happy to discuss the reasons behind it if it's not making sense :) |
I'll close mine my PR in favor of this one. |
Hi @janko, just following this up again. Do you have any feedback on the PR? Happy to change what needs changing. |
Thanks for the PR, and sorry for the delay. The implementation looks good to me, would you mind adding documentation to |
No worries at all. I've just pushed that change now. |
@brendon I was under the impression it would be called |
Oh right, re-read it now and got the issue. OK, I will see if I can fix that after merging, so that it can be called |
Thanks @janko, yea it was a bit of a mind-bender at the time :D Weird test failures going on there (not related to this PR by the looks...) Also happy to rename it in this PR if you make your mod on |
Not sure what's up with Ruby 2.6 & 2.7 failures, but I'll go ahead and merge this, and fix that afterwards. |
Thanks again :) Locally I was getting random test failures because of:
Re-running usually let them pass. That's on macOS but I suppose it could be a similar issue on the CI. |
Oh, maybe the test suite should be explicitly cleaning out tempfiles between runs. I might have upped the OS limit for file descriptors somewhere. I'm also on macOS. |
FYI, in 9d72e46 I added support for resize-on-load and renamed it back to |
Nice @janko! :) Looking forward to using it :D |
Hi @janko, no major rush, but would you mind doing a release with this update in it in the next few weeks? :) |
@brendon Just released 1.13.0 with this change 😉 |
Thanks @janko, much appreciated :) |
This method allows one to provide a desired size to cover (width and height) and the image will be resized maintaining the ratio so that it covers that box without cropping the other oversized dimension. This behaves similar to
object-fit: cover;
in CSS.I've tested that this works in my Active Storage code
image.file.variant(resize_to_cover: [696, 464])
but unfortunately I'm a bit confused about how the tests work. I need to know the dimensions of the image for the ratio calculations but the tests provide the file as a string. Is there something I can call in my
resize_to_cover
method to load the image so I can be sure I have the dimensions?