- md5
- 26f33dfd70365e3e75f33be23b21fd33
- sha1
- c6a910cc7c03b7c3855bfc050124d7c67c79f87e
- sha256
- 84b5a2174e5aa2c1b4946be441d23f476771a13dd9907ee83c812fed17839505
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
<?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
* @phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
*/
use Joomla\CMS\Image\Image;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Media Manager Resize Action
*
* @since 4.0.0
*/
class PlgMediaActionResize extends \Joomla\Component\Media\Administrator\Plugin\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_contents();
ob_end_clean();
}
}
The same content is in 22 releases, Joomla 4.2.7-rc1 to 4.3.4. See them all, or every version of this file.