CodeIgniter Forums
Image manipulation & cache - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Image manipulation & cache (/showthread.php?tid=58450)



Image manipulation & cache - El Forum - 06-13-2013

[eluser]Bondie[/eluser]
Is there a way of caching the dynamically generated images created with the image manipulation class or am I wasting my time?

Here is my simple code, it's messy I know, I need to tidy it up:
Code:
<?php

    class Assets extends CI_Controller{
        
        public function img ($method = 'resize', $w = 'original', $h = 'original', $src = '') {
            define("IMG_PATH", "assets/images/");
                        
            if ($src != NULL && !file_exists(IMG_PATH.$src)) {
                show_404();
            } else {                
                $config['image_library'] = 'gd2';
                $config['source_image'] = IMG_PATH.$src;
                $config['create_thumb'] = FALSE;
                $config['maintain_ratio'] = TRUE;
                $config['quality'] = '100%';
                if($w != 'original') $config['width'] = $w;
                if($h != 'original') $config['height'] = $h;
                $config['dynamic_output'] = TRUE;
                
                $this->load->library('image_lib', $config);

                if ( ! $this->image_lib->resize())
                {
                    echo $this->image_lib->display_errors();
                }
                
                $this->image_lib->clear();
            }
            
        }
        
    }

Some guidance and advice would be much appreciated!

EDIT
An example url would be:
Quote:www.example.com/assets/img/resize/100/100/picture.jpg



Image manipulation & cache - El Forum - 06-13-2013

[eluser]boltsabre[/eluser]
Isn't image caching handled by the browser which can be enabled/disabled/cleared by the user...?


Image manipulation & cache - El Forum - 06-13-2013

[eluser]Bondie[/eluser]
You're totally right, and I've thought about this the wrong way! Thank you for jogging my mind.


Image manipulation & cache - El Forum - 06-13-2013

[eluser]boltsabre[/eluser]
lol, no worries, happy to help.

Today I asked one of my colleges how we were going to handle a JS redirect and .htaccess, I thought that the .htaccess wouldn't work because it was a js redirect... brain fades happen all the time ;-)