Все же tinyjpg.com — автор тот же, там и png и jpg
Все же tinyjpg.com — автор тот же, там и png и jpg сжимаются.
Плагин выглядит так:
<?php
$e = &$modx->event;
if (!function_exists('optimizeJPG')) {
function optimizeJPG($file) {
$ext = strtolower(end(explode('.', $file)));
if ($ext == 'jpeg' || $ext == 'jpg') {
$cmd = '/usr/bin/jpegtran -optimize -progressive -copy none -outfile '.escapeshellarg($file.'_').' '.escapeshellarg($file);
exec($cmd, $result, $return_var);
if (file_exists ($file.'_') && filesize($file) > filesize($file.'_')) {
rename($file.'_',$file);
} else {
unlink($file.'_');
}
}
}
}
if ($e->name == "OnFileManagerUpload") {
$msProperties = $source->get('properties');
$path = realpath(MODX_BASE_PATH.$msProperties['basePath']['value'].$directory);
optimizeJPG($path.'/'.$files['file']['name']);
}