2011-08-16 3 views
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; 
    } 

의 크기 조정 코드는?

답변

16

먼저 어떤 경우에는 기본 크기 조정 도구를 그대로두면 편리 할 것입니다. 내가 한 것은 이미지 크기를 조정하는 두 가지 기능을 더 추가 한 것입니다.

관리자가 설정 한 크기에 맞게 이미지를 자르는 하나의 기능입니다. 이제 빈 흰색 영역이 추가됩니다. 이 제품은 제품 목록에 적합합니다. 두 번째로 추가 한 것은 이미지의 크기를 조정하여 가장 큰 치수가 관리자가 설정 한 최대 크기로 설정되도록하는 기능입니다. 비례에 맞게 조정됩니다.

새 파일은 posted in an OpenCart forum thread입니다.

나는 두 개의 추가 기능을 작물 크기onesize으로 명명했습니다. 당신이해야 할 모든 컨트롤러에서 사용되는 크기 조정 기능을 찾아이 조정된다

'thumb' => $this->model_tool_image 
       ->resize($image, 
         $this->config->get('config_image_category_width'), 
         $this->config->get('config_image_category_height'))); 

에를 :

'thumb' => $this->model_tool_image 
       ->cropsize($image, 
          $this->config->get('config_image_category_width'), 
          $this->config->get('config_image_category_height'))); 

ONESIZE 기능은 당신에게 달려 있으므로 하나 개의 매개 변수를 필요로하지만 당신은 사용할 수 있습니다 다음과 같이 입력하십시오 :

'popup' => $this->model_tool_image 
       ->onesize($result['image'], 
          $this->config->get('config_image_popup_width')) 

이 정보가 도움이되기를 바랍니다.

+0

내게 잘 맞습니다 (OpenCart 1.5.2.1). 이 코드를 게시 해 주셔서 감사합니다. – andrew

+1

OpenCart의 새 버전이 필요하기 때문에 고마워요, 작동합니다. model/tool/image.php의 마지막 else if 문을 변경했습니다. "return HTTPS_IMAGE. $ new_image;"대신 " 나는 "반환 $ this-> config-> get ('config_ssl'). 'image /'. $ new_image;"를 사용했습니다. 그리고 효과가있었습니다. – nikoloza

+0

이 방법이 효과가 있었지만 크기를 조정하거나 자르기 만하는 방법은 무엇입니까? – NewCod3r