Welcome Guest, Not a member yet? Register   Sign In
how to use Smart Image Resizer in codeigniter
#1

[eluser]Unknown[/eluser]
Does anyone have any idea how to use Smart Image Resizer in CI?
That script uses $_GET and I can't find anyway to make it work..
#2

[eluser]slowgary[/eluser]
The user guide talks about enabling query strings. You could also just run it from outside of the CI folder.
#3

[eluser]Unknown[/eluser]
I activated the query strings and it worksBig Grin

$config['enable_query_strings'] = TRUE;

Thanks for the idea.

I didn't know the default URL system works even if the query strings are activated.
#4

[eluser]Unknown[/eluser]
I have a simpler solution for the case. We need create a controller that will interpret following type of URL

Code:
http://<your_base_url>/imager/index/<image_width>-<image_height>-<crop_ratio>/<image_path>

To generate this type of URL, we will be using a function that will generate the above URL shown below.

Code:
if (!function_exists('imager')) {
    function imager($img_path,$width,$height,$aspect_ratio = NULL) {
        $img_fpath = 'imager/index/';
        $img_fpath .= $width."-".$height;
        $img_fpath .= '-';
        $img_fpath .= ($aspect_ratio)?$aspect_ratio:0;
        return site_url($img_fpath.'/'.$img_path);
    }

}

The controller which I discussed earlier for the purpose of resizing image is,

Code:
&lt;?php
class imager extends Controller{

    function index() {
       $whc = $this->uri->segment(3);
       $params = explode('-',$whc);
       $full_uri = $this->uri->uri_string();
       $img_final = str_replace('/imager/index/'.$whc.'/', '/', $full_uri);
       $data['img_path'] = $img_final;
       $data['img_width'] = $params[0];
       $data['img_height'] = $params[1];
       $data['img_aspect_ratio'] = $params[2];
       $this->load->view('common/imager',$data); //Smart Resizer codes are on this view file.
    }

}
/* End of file imager.php */
/* Location: ./application/controller/imager.php */

We can see that Smart Resizer has not appeared yet. The trick is that we will be putting the code of it in a view file. In my case, I've kept it on 'common/imager.php'.

Finally the usage is (of course on views):

Code:
&lt;?php $this->load->helper('yurl'); // the helper that contains the imager function.?&gt;
<img src="&lt;?=imager('uploads/image1.jpg',100,100,'1:1');?&gt;" />

I have added all the files on an attachment. Please help yourself. Since the forum does not allow the submission of zip file; I have renamed the extension of the zip attachment as doc so please rename extension to zip after you have downloaded. In windows you can do it like this way in command shell.
Code:
> ren application.doc application.zip




Theme © iAndrew 2016 - Forum software by © MyBB