<modification>
	<id>Polianna - system - library - image
	Polianna - catalog - model - tool</id>
	<version>1.5.5.1</version>
	<vqmver>2.1.7</vqmver>
	<author>polianna</author>
	<file name="system/library/image.php">
		<operation>
			<search position="before"><![CDATA[
				 public function resize($width = 0, $height = 0, $default = '') {
			]]></search>
			<add><![CDATA[
			
	    public function onesize($maxsize = 0) {
	    
	    	if (!$this->info['width'] || !$this->info['height']) {
	    		return;
	    	}
        
	        //afmetingen bepalen
	        $photo_width = $this->info['width']; 
	        $photo_height = $this->info['height'];
 	        
	        
	        // calculate dimensions
        	if ($photo_width > $maxsize OR $photo_height > $maxsize) {
		
		  if ($photo_width == $photo_height) {
		
		   $width = $maxsize;
		   $height = $maxsize;
		  
		   }else{
		  
			   $scale = $photo_width / $maxsize;
			  $width = $maxsize;
			$height = round ($photo_height / $scale);
		
		  }
		
		 }else{
		
		  $width = $photo_width;
		  $height = $photo_height;
		
		 }
	        	
	        // and bring it all to live	        
	       	$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, 0, 0, 0, 0, $width, $height, $photo_width, $photo_height);
	        imagedestroy($image_old);
	           
	        $this->info['width']  = $width;
	        $this->info['height'] = $height;

	    
	    }
			]]></add>
		</operation>
	</file>
	<file name="catalog/model/tool/image.php">
		<operation>
			<search position="before"><![CDATA[
				public function resize($filename, $width, $height, $type = "") {
			]]></search>
			<add><![CDATA[
			public function onesize($filename, $maxsize) {
	
		if (!file_exists(DIR_IMAGE . $filename) || !is_file(DIR_IMAGE . $filename)) {
			return;
		} 
		
		$info = pathinfo($filename);
		$extension = $info['extension'];
		
		$old_image = $filename;
		$new_image = 'cache/' . substr($filename, 0, strrpos($filename, '.')) . '-max-' . $maxsize . '.' . $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);
				}		
			}
			
			$image = new Image(DIR_IMAGE . $old_image);
			$image->onesize($maxsize);
			$image->save(DIR_IMAGE . $new_image);
		}
		
		if (isset($this->request->server['HTTPS']) && (($this->request->server['HTTPS'] == 'on') || ($this->request->server['HTTPS'] == '1'))) {
			return $this->config->get('config_ssl') . 'image/' . $new_image;
		} else {
			return $this->config->get('config_url') . 'image/' . $new_image;
		}	
			
	}	
			]]></add>
		</operation>
	</file>
</modification>