CoreFiles by mySites.guru
resize.php81 lines, 1,679 bytes, from Joomla_4.0.0-alpha6-Alpha-Full_Package.zip
Raw History Compare with 4.0.0-alpha5
md5
a428320bbb55a97a47e7f9695196c525
sha1
ac68e0fbb12d36fd37ee3543e4cb0ff307ad191c
sha256
551c9f5c3cb46a6f97514b2498bf75ec34b8d447bb52ef66115bda73fe4a92d5
<?php
/**
 * @package     Joomla.Plugin
 * @subpackage  Media-Action.resize
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

use Joomla\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 2 releases, Joomla 4.0.0-alpha5 to 4.0.0-alpha6. See them all, or every version of this file.