joomla-cms icon indicating copy to clipboard operation
joomla-cms copied to clipboard

[6.1] make media action crop aspect ratio configurable

Open hans2103 opened this issue 1 month ago • 44 comments

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:js to compile newly added js

  • Go To System > Plugins > Media-Action = Crop and notice ~~the availability of an aspect-ratio-calculator and~~ a subform to add / remove / edit aspect-ratio options. Add, remove and edit aspect ratios as you add them in css too... using 16 / 9, numbers with a slash

  • Save 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

Screenshot 2025-11-07 at 11 37 04 Screenshot 2025-11-07 at 11 37 31

Expected result AFTER applying this Pull Request

Screenshot 2025-12-02 at 10 33 51 Screenshot 2025-12-02 at 10 34 27

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

hans2103 avatar Nov 07 '25 10:11 hans2103

Nice, would be cool to default it with the existing values, so we can remove them when not needed.

laoneo avatar Nov 07 '25 14:11 laoneo

Nice, would be cool to default it with the existing values, so we can remove them when not needed.

@laoneo that has been taken care of.

https://github.com/joomla/joomla-cms/blob/1409e678d93cf4685d56dcfc34128252427aafb4/plugins/media-action/crop/crop.xml#L38

hans2103 avatar Nov 07 '25 15:11 hans2103

I have tested this item :white_check_mark: successfully on 65fcf2e628005ac42d6a1ecfa90b8e611aba58f0

Created a new aspect ratio and everything seems to work.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

RickR2H avatar Nov 14 '25 09:11 RickR2H

I have tested this item :white_check_mark: successfully on 65fcf2e628005ac42d6a1ecfa90b8e611aba58f0

Testes this, calculated my own crop ratio. copied it and added it to the bottom. Cropped an image using this new crop. All seems to work fine.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

TLWebdesign avatar Nov 19 '25 11:11 TLWebdesign

RTC


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

RickR2H avatar Nov 19 '25 13:11 RickR2H

I have tested this item :white_check_mark: successfully on 8d18b139a3351bdd5003f1c4e56489a994f6d87d


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

RickR2H avatar Nov 19 '25 16:11 RickR2H

Thank you for fixing those errors

brianteeman avatar Nov 19 '25 17:11 brianteeman

I have tested this item :white_check_mark: successfully on d79e1f754841efda2a60dde9a1279414d2561c14

Test by code review


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

RickR2H avatar Nov 19 '25 18:11 RickR2H

Sadly, @hans2103 when applying Download package on Joomla 6.1 Nightly downloaded 30 minutes ago on PHP 8.4.15, I get:

An error has occurred. 0 Error loading form file

(changed to PHP 8.3 and same result ;()

Testing process:

Fresh Nightly install, Sample Blog Data, French language file, Multilanguage Data, Regular Labs Cache Cleaner Joomla Patch Tester 5.0.0

Checked BEFORE condition of PR which were a match Download PR package and then went to check Media - Crop plugin ;(

exlemor avatar Nov 19 '25 19:11 exlemor

@hans2103 System tests would need some adjustment for this PR.

See https://github.com/joomla/joomla-cms/actions/runs/19510792565/job/55849853256?pr=46421 :

Running:  install/Installation.cy.js                                                    (1 of 148)

  Install Joomla
    1) "after each" hook for "Install Joomla"

  0 passing (14s)
  1 failing

  1) Install Joomla
       "after each" hook for "Install Joomla":
     CypressError: `cy.task('checkForLogs')` failed with the following error:

> [Wed Nov 19 17:43:33.751743 2025] [php:warn] [pid 263:tid 263] [client 127.0.0.1:47700] PHP Warning:  simplexml_load_file(): /tests/www/cmaria/plugins/media-action/crop/crop.xml:72: parser error : Opening and ending tag mismatch: fieldset line 25 and field in /tests/www/cmaria/libraries/src/Installer/Installer.php on line 2116, referer: https://localhost/cmaria/installation/index.php

And later those fail:

plugins/media-action/crop/CropPlugin.cy.js
plugins/media-action/resize/ResizePlugin.cy.js
plugins/media-action/rotate/RotatePlugin.cy.js

richard67 avatar Nov 19 '25 19:11 richard67

The system tests are correct!

brianteeman avatar Nov 19 '25 19:11 brianteeman

@exlemor you are correct. The XML is wrong as identified by the system tests

brianteeman avatar Nov 19 '25 19:11 brianteeman

Correction; the closing tag on line 39 is wrong it seems. although that doesn't fix the form completely if i change only that. Could be my install now but the calculator is broken atm. it just shows as a text field.

Scherm­afbeelding 2025-11-19 om 21 13 10

TLWebdesign avatar Nov 19 '25 20:11 TLWebdesign

@hans2103 System tests would need some adjustment for this PR.

See https://github.com/joomla/joomla-cms/actions/runs/19510792565/job/55849853256?pr=46421 :

Running:  install/Installation.cy.js                                                    (1 of 148)

  Install Joomla
    1) "after each" hook for "Install Joomla"

  0 passing (14s)
  1 failing

  1) Install Joomla
       "after each" hook for "Install Joomla":
     CypressError: `cy.task('checkForLogs')` failed with the following error:

> [Wed Nov 19 17:43:33.751743 2025] [php:warn] [pid 263:tid 263] [client 127.0.0.1:47700] PHP Warning:  simplexml_load_file(): /tests/www/cmaria/plugins/media-action/crop/crop.xml:72: parser error : Opening and ending tag mismatch: fieldset line 25 and field in /tests/www/cmaria/libraries/src/Installer/Installer.php on line 2116, referer: https://localhost/cmaria/installation/index.php

And later those fail:

plugins/media-action/crop/CropPlugin.cy.js
plugins/media-action/resize/ResizePlugin.cy.js
plugins/media-action/rotate/RotatePlugin.cy.js

the issue was caused by commit https://github.com/joomla/joomla-cms/pull/46421/commits/d79e1f754841efda2a60dde9a1279414d2561c14 I have reverted it.

hans2103 avatar Nov 20 '25 07:11 hans2103

Sorry I must have been incorrect. Clearly when there is a subform you dont close the field as I had assumed

brianteeman avatar Nov 20 '25 10:11 brianteeman

When in dark mode you can never see the calculated value and the button is hard to see

image image

I think this is caused by an already reported bug with the dark mode css when used in alerts

brianteeman avatar Nov 20 '25 10:11 brianteeman

The Calculated value doesnt use the same "rounding" as the default settings. Just seems odd/confusing/unexpected

image

brianteeman avatar Nov 20 '25 10:11 brianteeman

image

Default aspect ratio appear to be the calculated ratio of the original image so wouldnt it be more accurate to call it "original" and not "default" as I was looking for somewhere to set a "default" value thinking it would be defined somewhere globally

How is setting the ratio to default any different to none

brianteeman avatar Nov 20 '25 10:11 brianteeman

When in dark mode you can never see the calculated value and the button is hard to see

image image I think this is caused by an already reported bug with the dark mode css when used in alerts

Solved issue with commit https://github.com/joomla/joomla-cms/pull/46421/commits/c76424f822aab2bd6a3fb9aaca5ee0a42098eda7

hans2103 avatar Nov 20 '25 10:11 hans2103

image Default aspect ratio appear to be the calculated ratio of the original image so wouldnt it be more accurate to call it "original" and not "default" as I was looking for somewhere to set a "default" value thinking it would be defined somewhere globally

How is setting the ratio to default any different to none

@brianteeman I don't know... out of scope for my PR. That has been the case for the last 7 years already See commit https://github.com/joomla/joomla-cms/commit/145da22fdd8aef867638bf3087310bcde6d9f17a by @laoneo

hans2103 avatar Nov 20 '25 10:11 hans2103

The Calculated value doesnt use the same "rounding" as the default settings. Just seems odd/confusing/unexpected

image

The initial values where copied from the original. The original values where hard coded.

  • 2:3 was written as 0.6666666666666667
  • 16:9 was written as 1.7777777777777777

I do not think that the default settings are rounded... otherwise 16:9 would have been rounded to 1.7777777777777778

with commit https://github.com/joomla/joomla-cms/pull/46421/commits/f751bd23f28e6c1bf01cf5ce783f82a75a8cdc47 I have adjusted the default settings. No more odd / confusing / unexpected behavior and the same output as the calculator

hans2103 avatar Nov 20 '25 11:11 hans2103

Thanks.

I admit I never used it before as I have an odd ratio on my site. Now I can use it.

I still think default and none are confusing

brianteeman avatar Nov 20 '25 11:11 brianteeman

Thanks.

I admit I never used it before as I have an odd ratio on my site. Now I can use it.

I still think default and none are confusing

I do agree on the confusing part, but that is out of scope of this PR.

hans2103 avatar Nov 20 '25 13:11 hans2103

on dark mode the button outline becomes "invisible" because you have succes on succes with same color. Maybe change the copy button to btn-primary?

TLWebdesign avatar Nov 20 '25 13:11 TLWebdesign

I have tested this item :white_check_mark: successfully on 0a2c7857e2eee8660bd8a29111a6cf53d3273027


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

TLWebdesign avatar Nov 20 '25 14:11 TLWebdesign

I have tested this item :white_check_mark: successfully on 0a2c7857e2eee8660bd8a29111a6cf53d3273027


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

RickR2H avatar Nov 21 '25 08:11 RickR2H

Back to RTC after changes


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/46421.

RickR2H avatar Nov 21 '25 08:11 RickR2H

Screenshot 2025-11-21 at 12 56 21

I see "@brianteeman Requested changes with read-only permissions". But I am not able to see the requested changes. CAn you help me Brian? Otherwise... if all looks okay for this PR and the scope of this PR, please finish your review

hans2103 avatar Nov 21 '25 11:11 hans2103

I see no reason for the calculator, if you need to calculate it you have a calculator in your operating system

Added to make life easier for people. True.. I do have a calculator on my OS, but by adding this we can reduce the amount a user has to think.

Instead of adding this manually task I would prefer to allow simple calculations in the value

It's up to. you how you name it. A user might recognize A4 faster then 210x297 or Letter then 85x110

To name things your own way is the main reason I prefer a separation of ratio name and ratio value Hope you understand

hans2103 avatar Nov 28 '25 11:11 hans2103

To name things your own way is the main reason I prefer a separation of ratio name and ratio value

in my use case I intend to label then as per their usecase which will make it easier for my content authors. eg blog_thumbnail and blog_hero. They dont need to remember the dimensions or ratio just the usecase

brianteeman avatar Nov 28 '25 11:11 brianteeman