War*_*ace 5 php image-resizing opencart
我到处都看到如何在OpenCart中删除调整大小的图像但是没有发现任何相关信息.
我需要它调整大小但不保持比例.我希望图像就像我设置它一样.
这是system/library/image.php中的resize代码
public function resize($width = 0, $height = 0) {
if (!$this->info['width'] || !$this->info['height']) {
return;
}
$xpos = 0;
$ypos = 0;
$scale = min($width / $this->info['width'], $height / $this->info['height']);
if ($scale == 1) {
return;
}
$new_width = (int)($this->info['width'] * $scale);
$new_height = (int)($this->info['height'] * $scale);
$xpos = (int)(($width - $new_width) / 2);
$ypos = (int)(($height - $new_height) / 2);
$image_old = $this->image;
$this->image = imagecreatetruecolor($width, $height);
if (isset($this->info['mime']) && $this->info['mime'] == 'image/png') {
imagealphablending($this->image, false);
imagesavealpha($this->image, true);
$background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
imagecolortransparent($this->image, $background);
} else {
$background = imagecolorallocate($this->image, 255, 255, 255);
}
imagefilledrectangle($this->image, 0, 0, $width, $height, $background);
imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->info['width'], $this->info['height']);
imagedestroy($image_old);
$this->info['width'] = $width;
$this->info['height'] = $height;
}
Run Code Online (Sandbox Code Playgroud)
我可以删除该代码中的内容,以便图像不会保持调整大小的比例?
Jer*_*ohg 18
首先,我会保留默认的大小调整工具,因为在某些情况下它可能会派上用场.我所做的是添加两个函数来调整图像大小.
一个函数可以裁剪图像,使其符合管理员中设置的大小.现在添加了空白区域.这个非常适合产品清单.我添加的第二个是一个调整图像大小的功能,因此最大尺寸将设置为管理员中设置的最大尺寸.它将按比例缩放.
新文件发布在OpenCart论坛帖子中.
我将两个额外的函数命名为cropize和onesize.您所要做的就是在控制器中找到使用过的调整大小功能并调整:
'thumb' => $this->model_tool_image
->resize($image,
$this->config->get('config_image_category_width'),
$this->config->get('config_image_category_height')));
Run Code Online (Sandbox Code Playgroud)
至:
'thumb' => $this->model_tool_image
->cropsize($image,
$this->config->get('config_image_category_width'),
$this->config->get('config_image_category_height')));
Run Code Online (Sandbox Code Playgroud)
onesize函数只需要一个参数,所以它取决于你,但你可以使用这样的东西:
'popup' => $this->model_tool_image
->onesize($result['image'],
$this->config->get('config_image_popup_width'))
Run Code Online (Sandbox Code Playgroud)
我希望这能帮助你获得更好的图像.