-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[6.1] make media action crop aspect ratio configurable #46421
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
base: 6.1-dev
Are you sure you want to change the base?
[6.1] make media action crop aspect ratio configurable #46421
Conversation
Co-authored-by: Brian Teeman <brian@teeman.net>
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.
Pull request overview
This pull request adds configurable aspect ratios to the media crop plugin, allowing administrators to customize the available aspect ratio options through the plugin settings instead of being limited to hard-coded values.
Key Changes:
- Added a subform configuration in the plugin XML to allow administrators to define custom aspect ratios with labels, values (in fraction or decimal format), and optional grouping (landscape/portrait)
- Implemented
onContentPrepareFormmethod to dynamically inject custom aspect ratios into the crop form - Updated JavaScript to parse aspect ratio values in both fraction format (e.g., "16/9") and decimal format (e.g., "1.5")
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| plugins/media-action/crop/src/Extension/Crop.php | Adds form preparation logic to inject custom aspect ratios and return type declarations for loadJs/loadCss methods |
| plugins/media-action/crop/form/crop.xml | Updates default aspect ratio values from decimal to fraction format (e.g., "1.3333..." to "4/3") |
| plugins/media-action/crop/crop.xml | Adds configuration fieldset with subform for defining custom aspect ratios and references layouts folder |
| build/media_source/plg_media-action_crop/js/crop.es6.js | Adds parseAspectRatio function to handle both fraction and decimal aspect ratio formats |
| administrator/language/en-GB/plg_media-action_crop.ini | Adds language strings for the new aspect ratio configuration options |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| label="PLG_MEDIA-ACTION_CROP_RATIO_VALUE" | ||
| description="PLG_MEDIA-ACTION_CROP_RATIO_VALUE_DESC" | ||
| required="true" | ||
| pattern="([1-9]\d*/[1-9]\d*|[1-9]\d*)" |
Copilot
AI
Nov 30, 2025
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.
The regex pattern ([1-9]\d*/[1-9]\d*|[1-9]\d*) doesn't allow decimal values like "0.5" or "1.5" which the JavaScript parseAspectRatio function can handle via parseFloat(). Additionally, it doesn't allow single-digit values like "1" without additional digits. Consider updating the pattern to allow both fraction and decimal formats, e.g., ([1-9]\d*/[1-9]\d*|\d+\.?\d*) or (\d+/\d+|\d+\.?\d+) if you want to support zero-based values.
| pattern="([1-9]\d*/[1-9]\d*|[1-9]\d*)" | |
| pattern="(\d+/\d+|\d+\.?\d*)" |
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.
I do not want to support zero-based values.
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.
I do not want to support zero-based values.
that means you don't allow such values:
<option class="crop-aspect-ratio-option" value="0.8">4:5</option>
<option class="crop-aspect-ratio-option" value="0.75">3:4</option>
<option class="crop-aspect-ratio-option" value="0.6666666666666667">2:3</option>
<option class="crop-aspect-ratio-option" value="0.5625">9:16</option>
this options are all zero based.
I think we shouldn't force people to use the 1/2 since they might already get a 0.xyz value from another place and just want to copy paste it.
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.
I think we shouldn't force people to use the 1/2 since they might already get a 0.xyz value from another place and just want to copy paste it.
@HLeithner for real?
That is exactly what you suggested to do 4 days ago. Using a / to calculate implies adding as such too.
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.
You miss understand me, it's not a you MUST use x/y it's an optional thing. both should work. If I like to use 0.35 then that should be possible. But normally I would expect the more readable x/y variant.
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.
@HLeithner at this moment Joomla does not allow to configure any aspect ratios. This PR provides a solution that people can configure aspect ratios. At first I added a calculator to create the required value for the aspect ratios.
After your suggestion, which was very valid, I have removed the calculator and moved the calculation of the required value to javascript. People just have to enter the aspect ratio as if they add it in css too..... with a slash between the two numbers.
This PR as it is right now works like a charm. If other kind of input is needed for better UI, please create a new PR when this is merged and adjust it. But please... continue with the PR as it is right now.
|
Hello @hans2103 , It's a bit annoying to have to review vibe coding. If I see what correction Brian suggested and all this "small" mistakes. At the end it means, you saved some time for yourself and created a lot of new work for the reviewers. If you would have once reviewed and fixed the stuff by yourself it would have saved a lot of maintainer time. Also this AI generated blob at the end is just a waste of time for everyone reading it. I don't mind using AI to solve problems, but I would really like to see at least a review from yourself before the PR is created, don't push the work load to the maintainer. |
|
@bembelimen you're welcome for my attribution. Your personal feelings are not taken personal. But do keep in mind that I have reviewed the code myself too. But... I've been working on it for some time now and almost at the point of just giving up, convert it to a personal plugin and closing the PR. It just takes too much time to add a simple idea. Every new person inspecting the code has a new opinion on it. I will press "commit suggestion" as Copilot suggested and leave it as is. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ensures that aspect ratio values are properly escaped when added as attributes to XML elements. This prevents potential issues with special characters in the values, enhancing the robustness of the crop functionality.
|
@rdeutz @chmst Thank you both for the thumbs up in the comment of @bembelimen |
|
Usually language string keys are in the form _LABEL and _DESC. I woujld prefer it if you maintained this (undocumented) practice. So for example becomes |
|
@brianteeman thank you... I've added |
HLeithner
left a comment
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.
allow 0.35 and 1.35 beside 1/2 and 2/1 as value.
This PR only handles Please create a new PR for that if you like. |
not really only need to change the regex and the description for the field the rest works already as it should. Btw. I tested the pr and it works fine. |
can you create a PR on my PR with your suggestion? |
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
Co-authored-by: Allon Moritz <allon.moritz@digital-peak.com>
|
I have tested this item ✅ successfully on e7ff28e This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421. |
Pull Request for no issue
Summary of Changes
This PR will add a subform to plugin media-action/crop to give you the option to configure your own aspect-ratios.
With this PR merged I am able to create a own set of aspect ratios.
Testing Instructions
Go To System > Plugins > Media-Action = Crop and notice the lack of options
Go To Content > Media ... select the three dots of an image and press "Edit". Open the dropdown at Aspect-Ratio and notice the presence of a pre-defined set of aspect-ratios
Apply the PR
npm run build:jsto compile newly added jsGo To System > Plugins > Media-Action = Crop and notice
the availability of an aspect-ratio-calculator anda subform to add / remove / edit aspect-ratio options. Add, remove and edit aspect ratios as you add them in css too... using16 / 9, numbers with a slashSave the changes
Go To Content > Media ... select the three dots of an image and press "Edit". Open the dropdown at Aspect-Ratio and notice the changed set of aspect ratios
Actual result BEFORE applying this Pull Request
Expected result AFTER applying this Pull Request
Link to documentations
Please select:
Documentation link for docs.joomla.org:
No documentation changes for docs.joomla.org needed
Pull Request link for manual.joomla.org:
No documentation changes for manual.joomla.org needed