Created
April 1, 2020 16:01
-
-
Save ryandemmer/5605a441b01190cddbc1f4ccd37c49e3 to your computer and use it in GitHub Desktop.
Sample plugin to resize any image uploaded in Joomla / JCE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('JPATH_BASE') or die; | |
class PlgSystemUploadResize extends JPlugin | |
{ | |
public function onContentAfterSave($context, &$object_file) | |
{ | |
if (!preg_match('#^com_(media|jce)\.file$#', $context)) { | |
return; | |
} | |
if (!isset($object_file->filepath)) { | |
return; | |
} | |
$file = $object_file->filepath; | |
if (!is_file($file)) { | |
return; | |
} | |
// must be an image | |
if (!preg_match('#\.(jpg|jpeg|png)$#', $file)) { | |
return; | |
} | |
jimport('joomla.image.image'); | |
$image = new JImage($file); | |
// resize image to fit 800 x 600 | |
$image->resize(800, 600, false)->toFile($file); | |
// destroy handle | |
$image->destroy(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment