<?php
class Image_model extends CI_Model{
	
 	function image_model(){
  		//parent::CI_model();
		//LOAD library
		$this->load->library('image_lib');	
 	}
	
	
	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//DOWNSIZE THE DRAG N DROP IMAGE UPLOAD
	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	

	//downsize image
	function downsize_image($file){

		$config = array( 
		   'image_library' => 'GD2', 
		   'source_image' => ('./assets/images/' . $file),
		   'master_dim' => 'auto',
		   'width' => '800',
		  'height' => '1600',
		   'maintain_ratio' => true
		  ); 
		 
		 
		  $this->image_lib->initialize($config); 
		  if ( ! $this->image_lib->resize()) 
		  { 
			 	$data['error'] = $this->image_lib->display_errors();
			   	return $data;
		  } 
		  $this->image_lib->clear(); 
		 return;
		 }	


	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	//CROP -- 3 IMAGES $ GALLERY (thumb,cubed,original)
	//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++	
	
	function crop(){
			
			$x = $this->input->post('x');
			$y = $this->input->post('y');
			$pro_id = $this->input->post('pro_id');
			$img_id = $this->input->post('img_id');
			$filename = $this->input->post('filename');
			$gfolder = $this->input->post('gfolder');
			$folder = $this->input->post('folder');
			$targ_w = $this->input->post('targ_w');
			$targ_h = $this->input->post('targ_h');
			$o_wid = $this->input->post('o_wid');
			$o_hei = $this->input->post('o_hei');
			
			$x2 = $this->input->post('x2');
			$y2 = $this->input->post('y2');
			$w = $this->input->post('w');
			$h = $this->input->post('h');
				
				//THE MAGIC

				$configc['image_library'] = 'GD2';
				$configc['source_image'] = './assets/' . $pro_id . '/children/' . $filename ;
				$config['new_image'] = './assets/' . $pro_id . '/children/cover/' . $filename ;
					$configc['create_thumb'] = FALSE;
				$configc['maintain_ratio'] = FALSE;
				$configc['x_axis'] = $x;
				$configc['y_axis'] = $y;
				$configc['width'] = $w;
				$configc['height'] = $h;
	
				  $this->image_lib->initialize($configc); 
				  $this->image_lib->crop();
			
				$this->image_lib->clear();
				
				if ($h > $targ_h){
					
					//$this->downsize_thumb($filename);
				}

			//r$edirect
			return;
		
		}

}
?>