Want to resize image

edited December 2010 in News & Announcements
I have image field, and I want to do resize in 4 different size

In User Guide I found below property for image,

$upload_path = assets_server_path('authors/', 'images');
$fields['avatar_upload'] = array('type' => 'file', 'upload_path' => $upload_path, 'overwrite' => TRUE);

But didn't found anything related image resizing. So How Can I handle the image resizing?
If there is nothing inbuilt then please advise me, Where can I set my resizing code? So once Form submit then I can put my code there.

Comments

  • edited 2:42PM
    The 0.91 branch has an example website that includes a projects_model. In that projects_model we use the on_after_post model hook to further process the image. Below is what that looks like:
    
    function on_after_post($values)
    	{
    		$CI =& get_instance();
    		$CI->load->library('image_lib');
    		
    		// create the thumbnail if an image is uploaded
    		if (!empty($CI->upload))
    		{
    			$data = $CI->upload->data();
    			if (!empty($data['full_path']))
    			{
    				$thumb_img = assets_server_path('projects/'.$this->thumb_name($data['file_name']), 'images');
    				
    				// resize to proper dimensions
    				$config = array();
    				$config['source_image'] = $data['full_path'];
    				$config['create_thumb'] = FALSE;
    				//$config['new_image'] = $thumb_img;
    				$config['width'] = 240;
    				$config['height'] = 140;
    				$config['master_dim'] = 'auto';
    				$config['maintain_ratio'] = TRUE;
    				$CI->image_lib->clear();
    				$CI->image_lib->initialize($config);
    				if (!$CI->image_lib->resize())
    				{
    					$this->add_error($CI->image_lib->display_errors());
    				}
    				
    				// create thumb
    				$config = array();
    				$config['source_image'] = $data['full_path'];
    				$config['create_thumb'] = FALSE;
    				$config['new_image'] = $thumb_img;
    				$config['width'] = 100;
    				$config['height'] = 80;
    				$config['master_dim'] = 'auto';
    				$config['maintain_ratio'] = TRUE;
    				$CI->image_lib->clear();
    				$CI->image_lib->initialize($config);
    				if (!$CI->image_lib->resize())
    				{
    					$this->add_error($CI->image_lib->display_errors());
    				}
    			}
    		}
    
    		return $values;
    	}
    
  • edited 2:42PM
    aha thanks a lot, I'll try out this way.
  • edited 2:42PM
    if you want to resize image than i will you suggest you to visit the below link
    http://www.raiseitsolutions.com/forum/viewtopic.php?f=4&t=3
    please visit the link, here you can know about how to resize image.
    thank you very much.
  • edited 2:42PM
    What is this? this is an asp.net code.
    It seems you are spammer? or doing advertisement?
  • edited April 2011
    thats great. because of my logical global structure, i want to make that feature accessible to the whole fuel environment. Where do i have to add a hook, to upload predefined image-versions?
  • edited 2:42PM
    Currently, the above hook is only available on models.
  • edited 2:42PM
    Does this only work on a single image upload? how would you do this with more than one?

    Thanks
  • edited 2:42PM
    There is an array on the model that holds the uploaded image information called upload_data that you can access from within the on_after_post hook.
  • edited 2:42PM
    Got it, works like a treat!

    Thankyou
  • edited 2:42PM
    hi guys,if you wanna resizing images using VB.NET ,C#,or ASP.NET. PLz check .net image sdk ,more detail codes are seenable here .hope it will help someone in need.
    link is: http://www.rasteredge.com/how-to/vb-net-imaging/resize-image
Sign In or Register to comment.