Всем привет! В opencart 2.3 использую такой файл /catalog/model/tool/image.php (прикрепил файл к теме) который адаптивно обрезает изображения товаров и тд, без белых краев.
Вопрос - как сделать что бы он обрезал адаптивно не с центра начиная, а с самого верха фотки?
Буду рад бесплатной помощи, но если считаете что такая задача стоит денег - напишите в лс стоимость и сроки.
Дублирую текущий код сюда:
<?php
class ModelToolImage extends Model {
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;
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) {
$scaleW = $width_orig/$width;
$scaleH = $height_orig/$height;
$image = new Image(DIR_IMAGE . $old_image);
if ($scaleH > $scaleW) {
$_height = $height * $scaleW;
$top_x = 0;
$top_y = ($height_orig - $_height) / 2;
$bottom_x = $width_orig;
$bottom_y = $top_y + $_height;
$image->crop($top_x, $top_y, $bottom_x, $bottom_y);
} elseif ($scaleH < $scaleW) {
$_width = $width * $scaleH;
$top_x = ($width_orig - $_width) / 2;
$top_y = 0;
$bottom_x = $top_x + $_width;
$bottom_y = $height_orig;
$image->crop($top_x, $top_y, $bottom_x, $bottom_y);
}
$image->resize($width, $height, $type);
$image->save(DIR_IMAGE . $new_image);
} else {
copy(DIR_IMAGE . $old_image, DIR_IMAGE . $new_image);
}
}
if ($this->request->server['HTTPS']) {
return $this->config->get('config_ssl') . 'image/' . $new_image;
} else {
return $this->config->get('config_url') . 'image/' . $new_image;
}
}
}
image.php