- md5
- 70f7abee31bff1401c312339abd9b2c0
- sha1
- 203a71c09d91199092e5b47c6004f61933539db8
- sha256
- d5fce26e27d598dac9cf8978e034c0a0b7ccfeb7c9e6be74288338836967c085
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
<?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
*/
defined('_JEXEC') or die;
use Joomla\CMS\Image\Image;
/**
* 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 = array())
{
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 51 releases, Joomla 4.0.0-beta6 to 4.2.0-beta2. See them all, or every version of this file.