Skip to content

Commit

Permalink
Merge pull request #16 from abwebdevelopers/optimise-pageload-speeds
Browse files Browse the repository at this point in the history
Optimise pageload speeds by offloading resizing to an intermediary URL
  • Loading branch information
bradietilley authored Feb 4, 2020
2 parents 0375c49 + 0ea3bb5 commit 7232a28
Show file tree
Hide file tree
Showing 7 changed files with 407 additions and 74 deletions.
38 changes: 37 additions & 1 deletion Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@

use System\Classes\PluginBase;
use ABWebDevelopers\ImageResize\Classes\Resizer;
use ABWebDevelopers\ImageResize\Commands\ImageResizeClear;
use ABWebDevelopers\ImageResize\Commands\ImageResizeGc;
use Event;

class Plugin extends PluginBase
{
/**
* @inheritDoc
*/
public function pluginDetails()
{
return [
Expand All @@ -19,22 +24,30 @@ public function pluginDetails()
];
}

/**
* @inheritDoc
*/
public function registerMarkupTags()
{
return [
'filters' => [
'resize' => function ($image, $width, $height = null, $options = []) {
$resizer = new Resizer((string) $image);

return $resizer->resize((int) $width, (int) $height, (array) $options);
},
'modify' => function ($image, $options = []) {
$resizer = new Resizer((string) $image);

return $resizer->resize(null, null, (array) $options);
}
]
];
}

/**
* @inheritDoc
*/
public function registerSettings()
{
return [
Expand All @@ -50,14 +63,20 @@ public function registerSettings()
]
];
}


/**
* @inheritDoc
*/
public function registerPermissions()
{
return [
'abwebdevelopers.imageresize.access_settings' => ['tab' => 'abwebdevelopers.imageresize::lang.permissions.tab', 'label' => 'abwebdevelopers.imageresize::lang.permissions.access_settings'],
];
}

/**
* @inheritDoc
*/
public function boot()
{
Event::listen('backend.page.beforeDisplay', function ($controller, $action, $params) {
Expand All @@ -70,4 +89,21 @@ public function boot()
}
});
}

/**
* @inheritDoc
*/
public function register()
{
$this->registerConsoleCommand('imageresize:gc', ImageResizeGc::class);
$this->registerConsoleCommand('imageresize:clear', ImageResizeClear::class);
}

/**
* @inheritDoc
*/
public function registerSchedule($schedule)
{
$schedule->command('imageresize:gc')->daily();
}
}
Loading

0 comments on commit 7232a28

Please sign in to comment.