first commit
This commit is contained in:
41
plugins/media-action/resize/form/resize.xml
Normal file
41
plugins/media-action/resize/form/resize.xml
Normal file
@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form>
|
||||
<fieldset name="resize" label="PLG_MEDIA-ACTION_RESIZE_LABEL">
|
||||
<field
|
||||
name="resize_quality"
|
||||
type="number"
|
||||
label="PLG_MEDIA-ACTION_RESIZE_QUALITY"
|
||||
addonBefore="PLG_MEDIA-ACTION_RESIZE_QUALITY"
|
||||
min="1"
|
||||
max="100"
|
||||
step="1"
|
||||
default="80"
|
||||
filter="integer"
|
||||
/>
|
||||
|
||||
<field
|
||||
type="spacer"
|
||||
hr="true"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="resize_width"
|
||||
type="text"
|
||||
label="PLG_MEDIA-ACTION_RESIZE_PARAM_WIDTH"
|
||||
hiddenLabel="true"
|
||||
addonBefore="PLG_MEDIA-ACTION_RESIZE_PARAM_WIDTH"
|
||||
addonAfter="px"
|
||||
pattern="\d*\.?\d*"
|
||||
/>
|
||||
|
||||
<field
|
||||
name="resize_height"
|
||||
type="text"
|
||||
label="PLG_MEDIA-ACTION_RESIZE_PARAM_HEIGHT"
|
||||
hiddenLabel="true"
|
||||
addonBefore="PLG_MEDIA-ACTION_RESIZE_PARAM_HEIGHT"
|
||||
addonAfter="px"
|
||||
pattern="\d*\.?\d*"
|
||||
/>
|
||||
</fieldset>
|
||||
</form>
|
||||
47
plugins/media-action/resize/resize.xml
Normal file
47
plugins/media-action/resize/resize.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<extension type="plugin" group="media-action" method="upgrade">
|
||||
<name>plg_media-action_resize</name>
|
||||
<author>Joomla! Project</author>
|
||||
<creationDate>2017-01</creationDate>
|
||||
<copyright>(C) 2017 Open Source Matters, Inc.</copyright>
|
||||
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
|
||||
<authorEmail>admin@joomla.org</authorEmail>
|
||||
<authorUrl>www.joomla.org</authorUrl>
|
||||
<version>4.0.0</version>
|
||||
<description>PLG_MEDIA-ACTION_RESIZE_XML_DESCRIPTION</description>
|
||||
<namespace path="src">Joomla\Plugin\MediaAction\Resize</namespace>
|
||||
<files>
|
||||
<folder>form</folder>
|
||||
<folder plugin="resize">services</folder>
|
||||
<folder>src</folder>
|
||||
</files>
|
||||
<languages>
|
||||
<language tag="en-GB">language/en-GB/plg_media-action_resize.ini</language>
|
||||
<language tag="en-GB">language/en-GB/plg_media-action_resize.sys.ini</language>
|
||||
</languages>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset
|
||||
name="batch"
|
||||
label="PLG_MEDIA-ACTION_RESIZE_BATCH_LABEL"
|
||||
description="PLG_MEDIA-ACTION_RESIZE_BATCH_DESC"
|
||||
>
|
||||
|
||||
<field
|
||||
name="batch_width"
|
||||
type="text"
|
||||
label="PLG_MEDIA-ACTION_RESIZE_BATCH_MAX_WIDTH_LABEL"
|
||||
addonAfter="px"
|
||||
filter="integer"
|
||||
/>
|
||||
<field
|
||||
name="batch_height"
|
||||
type="text"
|
||||
label="PLG_MEDIA-ACTION_RESIZE_BATCH_MAX_HEIGHT_LABEL"
|
||||
addonAfter="px"
|
||||
filter="integer"
|
||||
/>
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
</extension>
|
||||
46
plugins/media-action/resize/services/provider.php
Normal file
46
plugins/media-action/resize/services/provider.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Media-Action.resize
|
||||
*
|
||||
* @copyright (C) 2023 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\Extension\PluginInterface;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\DI\Container;
|
||||
use Joomla\DI\ServiceProviderInterface;
|
||||
use Joomla\Event\DispatcherInterface;
|
||||
use Joomla\Plugin\MediaAction\Resize\Extension\Resize;
|
||||
|
||||
return new class () implements ServiceProviderInterface {
|
||||
/**
|
||||
* Registers the service provider with a DI container.
|
||||
*
|
||||
* @param Container $container The DI container.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.4.0
|
||||
*/
|
||||
public function register(Container $container): void
|
||||
{
|
||||
$container->set(
|
||||
PluginInterface::class,
|
||||
function (Container $container) {
|
||||
$plugin = new Resize(
|
||||
$container->get(DispatcherInterface::class),
|
||||
(array) PluginHelper::getPlugin('media-action', 'resize')
|
||||
);
|
||||
$plugin->setApplication(Factory::getApplication());
|
||||
|
||||
return $plugin;
|
||||
}
|
||||
);
|
||||
}
|
||||
};
|
||||
80
plugins/media-action/resize/src/Extension/Resize.php
Normal file
80
plugins/media-action/resize/src/Extension/Resize.php
Normal file
@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package Joomla.Plugin
|
||||
* @subpackage Media-Action.resize
|
||||
*
|
||||
* @copyright (C) 2017 Open Source Matters, Inc. <https://www.joomla.org>
|
||||
* @license GNU General Public License version 2 or later; see LICENSE.txt
|
||||
*/
|
||||
|
||||
namespace Joomla\Plugin\MediaAction\Resize\Extension;
|
||||
|
||||
use Joomla\CMS\Image\Image;
|
||||
use Joomla\Component\Media\Administrator\Plugin\MediaActionPlugin;
|
||||
|
||||
// phpcs:disable PSR1.Files.SideEffects
|
||||
\defined('_JEXEC') or die;
|
||||
// phpcs:enable PSR1.Files.SideEffects
|
||||
|
||||
/**
|
||||
* Media Manager Resize Action
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
final class Resize extends MediaActionPlugin
|
||||
{
|
||||
/**
|
||||
* The save event.
|
||||
*
|
||||
* @param string $context The context
|
||||
* @param object $item The item
|
||||
* @param boolean $isNew Is new item
|
||||
* @param array $data The validated data
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public function onContentBeforeSave($context, $item, $isNew, $data = [])
|
||||
{
|
||||
if ($context != 'com_media.file') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->params->get('batch_width') && !$this->params->get('batch_height')) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!\in_array($item->extension, ['jpg', 'jpeg', 'png', 'gif'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imgObject = new Image(imagecreatefromstring($item->data));
|
||||
|
||||
if ($imgObject->getWidth() < $this->params->get('batch_width', 0) && $imgObject->getHeight() < $this->params->get('batch_height', 0)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$imgObject->resize(
|
||||
$this->params->get('batch_width', 0),
|
||||
$this->params->get('batch_height', 0),
|
||||
false,
|
||||
Image::SCALE_INSIDE
|
||||
);
|
||||
|
||||
$type = IMAGETYPE_JPEG;
|
||||
|
||||
switch ($item->extension) {
|
||||
case 'gif':
|
||||
$type = IMAGETYPE_GIF;
|
||||
break;
|
||||
case 'png':
|
||||
$type = IMAGETYPE_PNG;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
$imgObject->toFile(null, $type);
|
||||
$item->data = ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user