⚠ 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 crud custom thumbnails size & path



amipax
  • profile picture
  • Member

Posted 13 May 2013 - 00:43 AM

Hi buddies,

 

  I'm successfully using image crud to upload my image files,  I need to have 1 custom size for my thumbnails of 210 in width and 140 in height. i also want to save the thumbnails in a folder called thumbnails in the same directory where original images are saved.

 

 assets/uploads  <-- original images reside here 

 assets/uploads/thumbnails <-- thumbnails reside here

 

  i found this inside the image_crud library

    protected function _create_thumbnail($image_path, $thumbnail_path)
    {
        $this->image_moo
            ->load($image_path)
            ->resize_crop(90,60)
            ->save($thumbnail_path,true);
    }

should i change values inside the library ->resize_crop(210,140)  or there's another way to it?

how do i assign the thumbnails path ?

 

thanks in advance


davidoster
  • profile picture
  • Member

Posted 13 May 2013 - 10:14 AM

Well to be honest it might be simpler to just change the _create_thumbnail but I suggest you don't.

 

Just extend the image_crud,

class Ext_image_ CRUD extends image_CRUD
{
	protected $_ci = null;

	public function __construct(){
		parent::__construct();
		$this->_ci = &get_instance();
	}

// extend here any functions you need modified


}

Under function render() there is a case called 'upload_file' (around line 516).

There you will see how the function is called and there you can define your custom path.


amipax
  • profile picture
  • Member

Posted 13 May 2013 - 20:42 PM

thnks davidoster,

 

 

  here's what i did ,i created Ext_image_crud.php

 
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include('image_crud.php');

class Ext_image_CRUD extends image_CRUD
{
    protected $_ci = null;
 

    public function __construct(){
        parent::__construct();
        $this->_ci = &get_instance();
    }

// extend here any functions you need modified
    public function _create_thumbnail($image_path, $thumbnail_path)
    {
        $this->image_moo
            ->load($image_path)
            ->resize_crop(210,140)
            ->save($thumbnail_path,true);
    }
    
}

 

 Unfortunately I still get 90,60 thumbnails,  should i copy paste all the image_crud methods and then make the respective changes in Ext_image_crud ?


davidoster
  • profile picture
  • Member

Posted 13 May 2013 - 21:52 PM

Can you please post the controller's code?


Piotr Nowak
  • profile picture
  • Member

Posted 26 February 2014 - 14:48 PM

Good topic

 

I've used code above and I get "Upload failed"

 

MY_image_crud.php

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
include('image_crud.php');

class MY_image_CRUD extends image_crud
{
    protected $_ci = null;

    public function __construct()
    {
	parent::__construct();
	$this->_ci = &get_instance();
    }

    public function _create_thumbnail($image_path, $thumbnail_path)
	{
	    $this->image_moo
			->load($image_path)
			->resize_crop(150,100)
			->save($thumbnail_path,true);
	}
    
}

and

Images_examples controller

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Images_examples extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		
		/* Standard Libraries */
		$this->load->database();
		/* ------------------ */
		
		$this->load->helper('url'); //Just for the examples, this is not required thought for the library
		
		$this->load->library('MY_image_crud');
	}
	
	function _example_output($output = null)
	{
		$this->load->view('example.php',$output);	
	}
	
	function index()
	{
		$this->_example_output((object)array('output' => '' , 'js_files' => array() , 'css_files' => array()));
	}	
	
	function example1()
	{
		$image_crud = new MY_image_crud();
		
		$image_crud->set_primary_key_field('id');
		$image_crud->set_url_field('url');
		$image_crud->set_table('example_1')
			->set_image_path('assets/uploads');
			
		$output = $image_crud->render();
		
		$this->_example_output($output);
	}
}

It doesnt work!


Donna111
  • profile picture
  • Member

Posted 26 March 2014 - 02:22 AM

HI there

Thanks for your suggestion.I am testing the image SDK which supports to custom size for my thumbnails automatically.Do you have any idea?Thanks for any suggestions.