Совершенно избыточная приблуда, которая решается тремя строчками кода, при наличии VPS.
Или на шареде на AdminVps.
Ставим optipng и jpegoptim (про mozjpeg - не надо сразу прошу сказок, гугл про эту чушь умалчивает).
На примере redhat/centos
yum install optipng
yum install jpegoptim
либо debian/ubuntu
apt-get install optipng
apt-get install jpegoptim
и потом меняем
catalog/model/tool/image.php на это!
<?php
class ModelToolImage extends Model {
/**
*
* @param filename string
* @param width
* @param height
* @param type char [default, w, h]
* default = scale with white space,
* w = fill according to width,
* h = fill according to height
*
*/
public function resize($filename, $width, $height, $type = "") {
if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
return;
}
$info = pathinfo($filename);
$extension = $info['extension'];
$old_image = $filename;
// $new_image = 'cache/' . utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type .'.' . $extension;
$currentLocal = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'ru_RU.UTF-8');
$pattern = [
'/\/\/+/',
'/\s/',
];
$replace = [
'/',
'-',
];
$new_image = 'cache/' . trim(escapeshellarg(preg_replace($pattern, $replace, urldecode(utf8_substr($filename, 0, utf8_strrpos($filename, '.')) . '-' . $width . 'x' . $height . $type .'.' . $extension))), '\'');
if (!file_exists(DIR_IMAGE . $new_image) || (filemtime(DIR_IMAGE . $old_image) > filemtime(DIR_IMAGE . $new_image))) {
$path = '';
$directories = explode('/', dirname(str_replace('../', '', $new_image)));
foreach ($directories as $directory) {
$path = $path . '/' . $directory;
if (!file_exists(DIR_IMAGE . $path)) {
@mkdir(DIR_IMAGE . $path, 0777);
}
}
list($width_orig, $height_orig) = getimagesize(DIR_IMAGE . $old_image);
if ($width_orig != $width || $height_orig != $height) {
$image = new Image(DIR_IMAGE . $old_image);
$image->resize($width, $height, $type);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
$img_log = new Log('img_log.log');
$optimized_image_path = escapeshellarg(DIR_IMAGE . $new_image);
if ($extension == 'jpeg' || $extension == 'jpg') {
$img_log->write(shell_exec("jpegoptim --max=80 --strip-all --all-progressive " . $optimized_image_path));
} elseif ($extension == 'png') {
$img_log->write(shell_exec("optipng -strip all -o7 ". $optimized_image_path ." 2>&1"));
}
}
return $this->getImageUrl($new_image);
}
protected function getImageUrl($new_image) {
$parts = explode('/', $new_image);
$new_url = implode('/', array_map('rawurlencode', $parts));
if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
return $this->config->get('config_ssl') . 'image/' . $new_url;
}
else {
return $this->config->get('config_url') . 'image/' . $new_url;
}
}
}
Вобщем две консольных команды и три строчки кода, не тянут на 1000 рублей никак!