Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2378ef9
make media action crop aspect ratio configurable
hans2103 Nov 7, 2025
c5ecf44
:art: code styling
hans2103 Nov 7, 2025
0a047f2
alpha sort
hans2103 Nov 7, 2025
13e8aa0
fix year
hans2103 Nov 7, 2025
2da2336
apply __DEPLOY_VERSION__ to newly added code
hans2103 Nov 7, 2025
daedb7c
fix year for newly added code
hans2103 Nov 7, 2025
436e14b
another sort :-)
hans2103 Nov 7, 2025
9850572
remove fallback Copy
hans2103 Nov 7, 2025
59a8091
Update administrator/language/en-GB/plg_media-action_crop.ini
hans2103 Nov 7, 2025
1409e67
PHPCBF FIX
hans2103 Nov 7, 2025
3c83c9a
Joomla.sanitizeHtml() for security
hans2103 Nov 9, 2025
65fcf2e
Merge branch '6.1-dev' into feature/6.1-media-action-crop-aspect-ratio
hans2103 Nov 9, 2025
db05b82
removal obsolete title attribute
hans2103 Nov 19, 2025
8d18b13
Merge branch '6.1-dev' into feature/6.1-media-action-crop-aspect-ratio
hans2103 Nov 19, 2025
d79e1f7
Update plugins/media-action/crop/crop.xml
hans2103 Nov 19, 2025
f6fc598
Revert "Update plugins/media-action/crop/crop.xml"
hans2103 Nov 20, 2025
c76424f
:wheelchair: removing className text-success to make text readable in…
hans2103 Nov 20, 2025
361715c
solve rounding issue
hans2103 Nov 20, 2025
392019c
Revert "solve rounding issue"
hans2103 Nov 20, 2025
f751bd2
adjust default setting to meet same output as calculator
hans2103 Nov 20, 2025
0a2c785
Change button class from success to primary
hans2103 Nov 20, 2025
325034c
removal of calculator
hans2103 Nov 28, 2025
5dea148
Enhances crop aspect ratio handling
hans2103 Nov 28, 2025
aaeb7bd
Merge branch '6.1-dev' into feature/6.1-media-action-crop-aspect-ratio
hans2103 Nov 28, 2025
afbc7d9
Updates crop aspect ratio values
hans2103 Nov 28, 2025
89e061c
Merge remote-tracking branch 'origin/feature/6.1-media-action-crop-as…
hans2103 Nov 28, 2025
5d1ee29
Normalizes aspect ratio handling for wider compatibility
hans2103 Nov 30, 2025
cdc90c2
Merge branch '6.1-dev' into feature/6.1-media-action-crop-aspect-ratio
hans2103 Nov 30, 2025
92750e7
Update plugins/media-action/crop/form/crop.xml
hans2103 Dec 1, 2025
e7ff28e
Update plugins/media-action/crop/crop.xml
hans2103 Dec 1, 2025
16cdeee
Update plugins/media-action/crop/src/Extension/Crop.php
hans2103 Dec 1, 2025
e2c998a
Update plugins/media-action/crop/crop.xml
hans2103 Dec 1, 2025
3449a2d
Update build/media_source/plg_media-action_crop/js/crop.es6.js
hans2103 Dec 1, 2025
402a702
Update plugins/media-action/crop/src/Extension/Crop.php
hans2103 Dec 1, 2025
4db306f
Escapes aspect ratio values
hans2103 Dec 1, 2025
b6f6637
add _LABEL to the keys
hans2103 Dec 2, 2025
016baa5
Update plugins/media-action/crop/src/Extension/Crop.php
hans2103 Dec 2, 2025
4dd59c1
Update plugins/media-action/crop/src/Extension/Crop.php
hans2103 Dec 2, 2025
1c104a4
Update plugins/media-action/crop/src/Extension/Crop.php
hans2103 Dec 2, 2025
71ee773
reduce complexity
hans2103 Dec 2, 2025
4b1256d
compact code
hans2103 Dec 2, 2025
042a355
even more compact. :-)
hans2103 Dec 2, 2025
ed574b1
undo removed spaces
hans2103 Dec 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions administrator/language/en-GB/plg_media-action_crop.ini
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
; Note : All ini files need to be saved as UTF-8

PLG_MEDIA-ACTION_CROP="Media Action - Crop"
PLG_MEDIA-ACTION_CROP_ASPECT_RATIOS_LABEL="Aspect Ratios"
PLG_MEDIA-ACTION_CROP_ASPECT_RATIOS_DESC="Configure custom aspect ratios for the crop tool. Each ratio needs a label (e.g. '16:9'), a value (e.g. '1.7777777777777777'), and optionally a group (landscape/portrait)."
PLG_MEDIA-ACTION_CROP_LABEL="Crop"
PLG_MEDIA-ACTION_CROP_PARAM_ASPECT="Aspect Ratio"
PLG_MEDIA-ACTION_CROP_PARAM_DEFAULT_RATIO="Default aspect ratio"
Expand All @@ -15,4 +17,19 @@ PLG_MEDIA-ACTION_CROP_PARAM_WIDTH="Width"
PLG_MEDIA-ACTION_CROP_PARAM_X="X-Axis"
PLG_MEDIA-ACTION_CROP_PARAM_Y="Y-Axis"
PLG_MEDIA-ACTION_CROP_QUALITY="Quality"
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_LABEL="Aspect Ratio Calculator"
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_DESC="Use this calculator to determine the decimal value for your aspect ratios. Enter width and height, then copy the calculated value."
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_HEIGHT_LABEL="Height"
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_WIDTH_LABEL="Width"
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_OUTPUT_LABEL="Calculated value:"
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_OUTPUT_TITLE_LABEL="Click to copy"
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_COPY_LABEL="Copy"
PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_COPY_DONE_LABEL="Copied"
PLG_MEDIA-ACTION_CROP_RATIO_GROUP="Group"
PLG_MEDIA-ACTION_CROP_RATIO_GROUP_DESC="Optionally group this ratio under landscape or portrait"
PLG_MEDIA-ACTION_CROP_RATIO_GROUP_NONE="No group"
PLG_MEDIA-ACTION_CROP_RATIO_LABEL="Label"
PLG_MEDIA-ACTION_CROP_RATIO_LABEL_DESC="The label to display for this ratio (e.g. '16:9', '4:3', etc.)"
PLG_MEDIA-ACTION_CROP_RATIO_VALUE="Value"
PLG_MEDIA-ACTION_CROP_RATIO_VALUE_DESC="The calculated aspect ratio value (width/height). For example, 16:9 = 1.7777777777777777, 4:3 = 1.3333333333333333, 1:1 = 1"
PLG_MEDIA-ACTION_CROP_XML_DESCRIPTION="Adds crop functionality for images."
17 changes: 17 additions & 0 deletions build/media_source/plg_media-action_crop/joomla.asset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json",
"name": "plg_media-action_crop",
"version": "6.1.0",
"description": "Web Assets for Media Action Crop Plugin",
"license": "GPL-2.0-or-later",
"assets": [
{
"name": "plg_media-action_crop.calculator",
"type": "script",
"uri": "plg_media-action_crop/calculator.js",
"attributes": {
"defer": true
}
}
]
}
111 changes: 111 additions & 0 deletions build/media_source/plg_media-action_crop/js/calculator.es6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/**
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

/**
* Aspect Ratio Calculator Module
*/
(() => {
const initCalculator = () => {
const widthInput = document.getElementById('calc-width');
const heightInput = document.getElementById('calc-height');
const output = document.getElementById('calc-output');
const copyBtn = document.getElementById('copy-calc-value');

if (!widthInput || !heightInput || !output || !copyBtn) {
return;
}

/**
* Calculate aspect ratio from width and height
*/
const calculateRatio = () => {
const width = parseFloat(widthInput.value);
const height = parseFloat(heightInput.value);

if (width > 0 && height > 0) {
const ratio = width / height;
output.textContent = ratio.toString();
} else {
output.textContent = '0';
}
};

/**
* Show copy feedback on button
*/
const showCopyFeedback = () => {
const originalHTML = copyBtn.innerHTML;
const copiedIcon = copyBtn.getAttribute('data-copied-icon');
const copiedText = copyBtn.getAttribute('data-copied-text');

copyBtn.innerHTML = copiedIcon + copiedText;
copyBtn.disabled = true;

setTimeout(() => {
copyBtn.innerHTML = originalHTML;
copyBtn.disabled = false;
}, 2000);
};

/**
* Fallback copy method for older browsers
*
* @param {string} value - The value to copy
*/
const fallbackCopy = (value) => {
const textArea = document.createElement('textarea');
textArea.value = value;
textArea.style.position = 'fixed';
textArea.style.left = '-999999px';
document.body.appendChild(textArea);
textArea.select();

try {
document.execCommand('copy');
showCopyFeedback();
} catch (err) {
// Silent fail
}

document.body.removeChild(textArea);
};

/**
* Copy the calculated value to clipboard
*/
const copyToClipboard = () => {
const value = output.textContent;

if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(value)
.then(() => {
showCopyFeedback();
})
.catch(() => {
fallbackCopy(value);
});
} else {
fallbackCopy(value);
}
};

// Attach event listeners
widthInput.addEventListener('input', calculateRatio);
heightInput.addEventListener('input', calculateRatio);
copyBtn.addEventListener('click', copyToClipboard);
output.addEventListener('click', copyToClipboard);

// Calculate initial ratio
calculateRatio();
};

// Initialize when DOM is ready
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initCalculator);
} else {
// DOM already loaded, run with slight delay for form rendering
setTimeout(initCalculator, 100);
}
})();
54 changes: 54 additions & 0 deletions plugins/media-action/crop/crop.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,65 @@
<namespace path="src">Joomla\Plugin\MediaAction\Crop</namespace>
<files>
<folder>form</folder>
<folder>layouts</folder>
<folder plugin="crop">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_media-action_crop.ini</language>
<language tag="en-GB">language/en-GB/plg_media-action_crop.sys.ini</language>
</languages>
<config>
<fields name="params" addfieldprefix="Joomla\Plugin\MediaAction\Crop\Field">
<fieldset name="basic">
<field
name="ratio_calculator"
type="calculator"
label="PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_LABEL"
/>
<field
name="aspect_ratios"
type="subform"
label="PLG_MEDIA-ACTION_CROP_ASPECT_RATIOS_LABEL"
description="PLG_MEDIA-ACTION_CROP_ASPECT_RATIOS_DESC"
multiple="true"
layout="joomla.form.field.subform.repeatable-table"
default='{"aspect_ratios0":{"label":"1:1","value":"1","group":""},"aspect_ratios1":{"label":"5:4","value":"1.25","group":"landscape"},"aspect_ratios2":{"label":"4:3","value":"1.3333333333333333","group":"landscape"},"aspect_ratios3":{"label":"3:2","value":"1.5","group":"landscape"},"aspect_ratios4":{"label":"16:9","value":"1.7777777777777777","group":"landscape"},"aspect_ratios5":{"label":"4:5","value":"0.8","group":"portrait"},"aspect_ratios6":{"label":"3:4","value":"0.75","group":"portrait"},"aspect_ratios7":{"label":"2:3","value":"0.6666666666666667","group":"portrait"},"aspect_ratios8":{"label":"9:16","value":"0.5625","group":"portrait"}}'
>
<form>
<field
name="label"
type="text"
label="PLG_MEDIA-ACTION_CROP_RATIO_LABEL"
description="PLG_MEDIA-ACTION_CROP_RATIO_LABEL_DESC"
required="true"
filter="string"
/>
<field
name="value"
type="text"
label="PLG_MEDIA-ACTION_CROP_RATIO_VALUE"
description="PLG_MEDIA-ACTION_CROP_RATIO_VALUE_DESC"
required="true"
pattern="\d*\.?\d+"
hint="1.7777777777777777"
validate="number"
class="input-small"
/>
<field
name="group"
type="list"
label="PLG_MEDIA-ACTION_CROP_RATIO_GROUP"
description="PLG_MEDIA-ACTION_CROP_RATIO_GROUP_DESC"
default=""
>
<option value="">PLG_MEDIA-ACTION_CROP_RATIO_GROUP_NONE</option>
<option value="landscape">PLG_MEDIA-ACTION_CROP_PARAM_LANDSCAPE</option>
<option value="portrait">PLG_MEDIA-ACTION_CROP_PARAM_PORTRAIT</option>
</field>
</form>
</field>
</fieldset>
</fields>
</config>
</extension>
75 changes: 75 additions & 0 deletions plugins/media-action/crop/layouts/field/calculator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Media-Action.crop
*
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

\defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;

extract($displayData);

/**
* Layout variables
* -----------------
* @var string $id The field ID
*/

// Load the calculator JavaScript
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->getRegistry()->addExtensionRegistryFile('plg_media-action_crop');
$wa->useScript('plg_media-action_crop.calculator');

// Prepare data for JavaScript
$copiedIcon = LayoutHelper::render('joomla.icon.iconclass', ['icon' => 'icon-check']);
$copiedText = Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_COPY_DONE_LABEL');
?>
<div class="card mb-3">
<div class="card-header">
<h2 id="aspect-ratio-calculator" class="card-title mb-0">
<?php echo LayoutHelper::render('joomla.icon.iconclass', ['icon' => 'icon-wand']); ?>
<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_LABEL'); ?>
</h2>
</div>
<div class="card-body">
<p class="mb-3">
<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_DESC'); ?>
</p>
<div class="row g-3 mb-3">
<div class="col-md-6">
<label for="calc-width" class="form-label fw-bold">
<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_WIDTH_LABEL'); ?>
</label>
<input type="number" id="calc-width" min="1" step="1" value="16" class="form-control" />
</div>
<div class="col-md-6">
<label for="calc-height" class="form-label fw-bold">
<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_HEIGHT_LABEL'); ?>
</label>
<input type="number" id="calc-height" min="1" step="1" value="9" class="form-control" />
</div>
</div>
<div class="alert alert-success d-flex align-items-center justify-content-between" role="alert">
<div>
<strong class="me-2">
<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_OUTPUT_LABEL'); ?>
</strong>
<output id="calc-output" for="aspect-ratio-calculator" class="font-monospace fs-5 text-success fw-bold user-select-all" style="cursor: pointer;" title="<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_OUTPUT_TITLE_LABEL'); ?>">1.7777777777777777</output>
</div>
<button type="button" id="copy-calc-value" class="btn btn-success btn-sm"
title="<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_COPY_LABEL'); ?>"
data-copied-icon="<?php echo htmlspecialchars($copiedIcon, ENT_QUOTES, 'UTF-8'); ?>"
data-copied-text="<?php echo htmlspecialchars($copiedText, ENT_QUOTES, 'UTF-8'); ?>">
<?php echo LayoutHelper::render('joomla.icon.iconclass', ['icon' => 'icon-copy']); ?>
<?php echo Text::_('PLG_MEDIA-ACTION_CROP_RATIO_CALCULATOR_COPY_LABEL'); ?>
</button>
</div>
</div>
</div>
Loading
Loading