⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

image size problem



Umair Memon

Umair Memon
  • profile picture
  • Member

Posted 18 January 2014 - 13:56 PM

i have question is that when i was run the employees_management example this is ok means the image size are automatic resize in small but when this example i was use in my site there is image size problem means when ever i upload large this will not resize automaticaly plzzzzzzz can any body solve it this my code :(

 

 

 

 

public function publisher()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$this->config->set_item('grocery_crud_file_upload_allow_file_types','gif|jpeg|jpg|png');
$this->db = $this->load->database('default',true);
 
$crud->set_table('publication');
 
$crud->set_subject('Publish Books');
$crud->required_fields('p_tiltle','p_year','p_prize','p_image');
 
$crud->set_field_upload('p_image','assets/uploads/files');
$output = $crud->render();
 
$this->_example_output($output);
}
 

 


Donna111

Donna111
  • profile picture
  • Member

Posted 26 January 2014 - 06:52 AM

Hi there

It is indeed difficult to do that using a code.There are many fine third party tool which supports to resize the image directly.So why don't you try to add one of the

powerful image processing tool to help you out.And you can just try their free trial.


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 29 January 2014 - 08:34 AM

Hello Umair Memon

 

What is exactly that u want in... when u uploading large image.. u want to resize the image?

that u can do it using callback_after_insert ... or if u insist on resizing the uploaded image.. u can do a callback after upload ...

This will help u do a resized upload and store...

but if u insists on a workout like keep the images large enough and also enjoy the speed ... then u need to extract the addon from my code i shared earlier

/topic/2289-power-grocerycrud/

u can refer to the url .. and there u will find i have shared an addon library ...img.php ...and integrated it with grocery cruds primary library ...  what is the purpose of it is to generate small thumbnail images for runtime (display on list / view / edit form) and on click of it.. open the actual image file...

u surely are most welcome to extract that functionality and enjoy the benefits of the same

 

Happy GCing :)


Kun Hernowo Putra

Kun Hernowo Putra
  • profile picture
  • Member

Posted 24 February 2014 - 04:27 AM

Hello Amit  cani upload resize image this 

 public function banner(){
        
        
        if($this->session->userdata('logged_in')){
            $session_data = $this->session->userdata('logged_in');
            $data['username'] = $session_data['username'];
            $this->load->view('administrator', $data);
        }
        else{
            redirect('login','refresh');
        }
        
        $crud = new grocery_CRUD();
        $crud->set_table('banner');
        $crud->set_subject('Banner');
        $crud->required_fields('bannerImage','bannerImage600','bannerImage370','bannerTitle','active');
        $crud->columns('bannerTitle','bannerDescription','bannerImage','active');
        $crud->display_as('sortOrder', 'Sort Order');
        $crud->display_as('bannerTitle', 'Banner Title');
        $crud->display_as('bannerDescription', 'Banner Description');
        $crud->display_as('bannerImage', 'Banner Image Large');
		$crud->display_as('bannerImage600', 'Banner Image Medium');
		$crud->display_as('bannerImage370', 'Banner Image Small');
        $crud->field_type('dateAdd', 'hidden');
        $crud->field_type('dateEdit', 'hidden');
        
        $crud->set_field_upload('bannerImage','../images/banner');
		$crud->set_field_upload('bannerImage370','../images/banner');
		$crud->set_field_upload('bannerImage600','../images/banner');
        $crud->set_relation('active','aktivasi','active');
        
		$crud->callback_after_upload(array($this,'example_callback_after_upload'));
        $crud->callback_before_delete(array($this, 'delete_banner_image'));
        $crud->unset_export();
        $crud->unset_print();
        
        $output = $crud->render();
        $this->banner_crud($output);
              
    }

    public function banner_crud($output = NULL){
        
        $this->load->view('banner.php',$output);
    }
    
	function example_callback_after_upload($uploader_response,$field_info, $files_to_upload)
{
    $this->load->library('image_moo');
 
    //Is only one file uploaded so it ok to use it with $uploader_response[0].
    $bannerImage = $field_info->upload_path.'/'.$uploader_response[0]->name; 
	$bannerImage600 = $field_info->upload_path.'/'.$uploader_response[0]->name;
	$bannerImage370 = $field_info->upload_path.'/'.$uploader_response[0]->name;
 
    $this->image_moo->load($bannerImage)->set_jpeg_quality(90);
	$this->image_moo->load($bannerImage600)->resize_crop(600,600)->save($bannerImage600,true);
	$this->image_moo->load($bannerImage370)->resize_crop(370,370)->save($bannerImage370,true);
 
    return true;
}

With my datebase
$bannerImage600 and $bannerImage370


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 24 February 2014 - 16:38 PM

Hi Kun Hernowo Putra

 

What i notice an issue here in the code that u have written after upload is - u u resizing the same image from original to 600x600 and then to 370x370

Rather - then doing such a thing what i will recommend u doing is have 2 folders inside the image path and there is where u create the resized images

function example_callback_after_upload($uploader_response,$field_info, $files_to_upload)
{
    $this->load->library('image_moo');
 
    //Is only one file uploaded so it ok to use it with $uploader_response[0].
    $bannerImage = $field_info->upload_path.'/'.$uploader_response[0]->name; 
	
	$600path = $bannerImage600 = $field_info->upload_path.'/600';
	$370path = $bannerImage600 = $field_info->upload_path.'/370';
	
	if (!file_exists($600path)) {
		mkdir($600path, 0777);
	}
	if (!file_exists($370path)) {
		mkdir($370path, 0777);
	}
	
	$bannerImage600 = $600path.'/'.$uploader_response[0]->name ;
	$bannerImage370 = $370path.'/'.$uploader_response[0]->name;
 
    $this->image_moo->load($bannerImage)->set_jpeg_quality(90);
	$this->image_moo->load($bannerImage)->resize_crop(600,600)->save($bannerImage600,true);
	$this->image_moo->load($bannerImage)->resize_crop(370,370)->save($bannerImage370,true);
 
    return true;
}

Well this way u

1 - make sure that the u dont overwrite the same image ...

2 - Store separate images of separate resolutions in separate folders

3 - u don't need to store back the image names in here - u can just let go with the same .. as u have distinct folders for image image - and u have the same image name for all so this suffice the need without any issue.