Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise pageload speeds by offloading resizing to an intermediary URL #16

Merged
merged 9 commits into from
Feb 4, 2020
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