4
我已經到處尋找如何刪除OpenCart中調整大小的圖像,但沒有發現任何相關信息。刪除OpenCart中的圖像調整大小比例
我需要它調整大小,但不要保持比例。我想讓圖像像我設置的一樣。
這裏的系統/庫/ image.php
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;
}
在該代碼我能怎麼去除,因此圖像不保持它在調整大小比例調整大小的代碼?
這對我很有用(OpenCart 1.5.2.1)。感謝您發佈此代碼。 – andrew
謝謝,它的工作原理,只是我在model/tool/image.php中更改了最後一個else語句,因爲我認爲新版本的OpenCart需要這樣做。而不是「返回HTTPS_IMAGE。$ new_image;」我用「return $ this-> config-> get('config_ssl')。'image /'。$ new_image;」它的工作。 – nikoloza
這工作,但如何調整/裁剪寬度只? – NewCod3r