Modx Gallery Upload Event
Hello everyone There is a website on modx. I use the Gallery and PhpThumbOn plugins. I want to connect webp images to the site. modx has a system event OnFileManagerUpload which is triggered when a file is uploaded via a standard file manager:
<?php
if ($modx->event->name!='OnFileManagerUpload')
return;
$file_info=pathinfo($files['file']['name']);
$ext=strtolower($file_info['extension']);
$dir=MODX_BASE_PATH . $directory;
$file=$dir . $files['file']['name'];
if (($ext=="jpg" || $ext=="jpeg") && $files['file']['type']=='image/jpeg'){
$img = imageCreateFromJpeg($file);
}
if ($ext=="png" && $files['file']['type']=='image/png'){
$img = imageCreateFromPng($file);
}
imageWebp($img, $dir . $file_info['filename'] . '.' . 'webp');
imagedestroy($img);
This works (images are converted to webp), but only when uploaded via the standard file manager:
But if I upload via the Gallery plugin a copy of the jpg (in webp) does not created.:
Question: How do I create an event so that the plugin works when loading from Gallery? Or which event should I use if it's already built in? I didn't find anything about Events in the gallery documentation
Thanks!
0
Author: Kamil NHOT, 2020-10-23