Main menu
WalkswithMeJoomlaJoomla Media File Optimize Plugin

Joomla Media File Optimize Plugin

Joomla media file optimize plugin can be used to create different instance of your media files especially your banner images. This plugin is dealing with banner images and assumes that all the images, So basically the images in other location they do not create instances this is due to I hard code the path  in the plugin you can changes the path or set it manageable from plugin params.

Joomla media file optimize plugin creates 2 different thumbnail for your banner images with your custom size with proportion.The point of this article is not just providing such a plugin the importance of the  onContentAfterSave($context, &$article, $isNew) . event in Joomla.

  onContentAfterSave can be used as a hook for your media files, so using this method you can optimize your media file and have full control over the media items with an external plugin sounds good right ?

Joomla media file optimize plugin

Joomla media file optimize plugin

Yes that is the important of Joomla media file optimize plugin, you can create more efficient plugin with this event for image optimization like compress image size with jpegtran or pngout etc.

Now just take a look at the function event of the Joomla media file optimize plugin.


public function onContentAfterSave($context, &$article, $isNew)
{
if($context == 'com_media.file'){
$tmbImgWidth     = $this->params->get('width',200);
$tmbImgHeight     = $this->params->get('height',150);
require_once(JPATH_SITE."/plugins/content/wwmmeadiaresize/class.img2thumb.php");
$dst1 = JPATH_SITE.'/images/banners/resized/'.$article->name;
$src = JPATH_SITE.'/images/banners/'.$article->name;
$dir1 = JPATH_SITE.'/images/banners/resized/';
if (!file_exists($dir1)) {
mkdir($dir1,0755);
}
list($imgTmbW, $imgTmbH, $imgTmbType, $imgTmbattr) = getimagesize($src);
if(file_exists($src))
$neu = new Img2Thumb( $src, $tmbImgWidth, $tmbImgHeight, $dst1, 0, 255, 255, 255 );
//Mobile version Image
$tmbImgWidth     = $this->params->get('width1',640);
$tmbImgHeight     = $this->params->get('height1',400);
require_once(JPATH_SITE."/plugins/content/wwmmeadiaresize/class.img2thumb.php");
$dst1 = JPATH_SITE.'/images/banners/mobile/'.$article->name;
$src = JPATH_SITE.'/images/banners/'.$article->name;
$dir2 = JPATH_SITE.'/images/banners/mobile/';
if (!file_exists($dir2)) {
mkdir($dir2,0755);
}
list($imgTmbW, $imgTmbH, $imgTmbType, $imgTmbattr) = getimagesize($src);
if(file_exists($src))
$neu = new Img2Thumb( $src, $tmbImgWidth, $tmbImgHeight, $dst1, 0, 255, 255, 255 );
return true;
}else{
return false;
}

Yes you can improve the function with checking image types and format or add some restrictions on file size etc. Hope this article will help you guys to create a plugin for managing your Joomla media files.

Thanks for reading 🙂 🙂 🙂

Download1166 downloads

Leave a Reply

Your email address will not be published. Required fields are marked *

 

FacebookTwitterGoogle+RSS