diff --git a/README.md b/README.md index fdff1c9..203760a 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,9 @@ Number of seconds before the browser checks the server for a new version of the **cache_dir:** 'cache/' Path to the image cache directory you would like to use, don't forget the trailing slash! +**source_dir:** `''` +Path prefix to the source directory you would like to use, don't forget the trailing slash! + **mimic_source_dir:** TRUE Mimic the source file folder structure within the cache directory. Useful if you want to keep track of cached files and folders to perhaps periodically clear some cache folders but not others. diff --git a/classes/ImageFly.php b/classes/ImageFly.php index fc842ba..9b1b430 100644 --- a/classes/ImageFly.php +++ b/classes/ImageFly.php @@ -18,6 +18,11 @@ class ImageFly * or processed sub directories when the "mimic_source_dir" config option id set to TRUE */ protected $cache_dir = NULL; + + /** + * @var string Stores the path to the source directory (set in the config "source_dir") + */ + protected $source_dir = NULL; /** * @var object Kohana image instance @@ -64,6 +69,8 @@ public function __construct() // Set the config $this->config = Kohana::$config->load('imagefly'); + + $this->source_dir = $this->config['source_dir']; // Try to create the cache directory if it does not exist $this->_create_cache_dir(); @@ -72,7 +79,7 @@ public function __construct() $this->_set_params(); // Set the source file modified timestamp - $this->source_modified = filemtime($this->source_file); + $this->source_modified = filemtime($this->source_dir.$this->source_file); // Try to create the mimic directory structure if required $this->_create_mimic_cache_dir(); @@ -155,7 +162,7 @@ private function _set_params() throw new HTTP_Exception_404('The requested URL :uri was not found on this server.', array(':uri' => Request::$current->uri())); - $this->image = Image::factory($filepath); + $this->image = Image::factory($this->source_dir.$filepath); // The parameters are separated by hyphens $raw_params = explode('-', $params); @@ -228,7 +235,7 @@ private function _cached_exists() */ private function _cached_required() { - $image_info = getimagesize($this->source_file); + $image_info = getimagesize($this->source_dir.$this->source_file); if (($this->url_params['w'] == $image_info[0]) AND ($this->url_params['h'] == $image_info[1])) { @@ -371,7 +378,7 @@ private function _serve_file() // Set either the source or cache file as our datasource if ($this->serve_default) { - $file_data = $this->source_file; + $file_data = $this->source_dir.$this->source_file; } else { diff --git a/config/imagefly.php b/config/imagefly.php index fa02caa..1e217dd 100644 --- a/config/imagefly.php +++ b/config/imagefly.php @@ -16,6 +16,10 @@ * Path to the image cache directory you would like to use, don't forget the trailing slash! */ 'cache_dir' => 'cache/', + /** + * Path to the image cache directory you would like to use, don't forget the trailing slash! + */ + 'source_dir' => '', /** * Mimic the source file folder structure within the cache directory. * Useful if you want to keep track of cached files and folders to perhaps periodically clear some cache folders but not others. @@ -28,13 +32,13 @@ /** * If the image should be scaled up beyond it's original dimensions on resize. */ - 'scale_up' => FALSE, - /** + 'scale_up' => FALSE, + /** * Will only allow param configurations set in the presets. * Best enabled on production sites to reduce spamming of different sized images on the server. */ - 'enforce_presets' => FALSE, - /** + 'enforce_presets' => FALSE, + /** * Imagefly params that are allowed when enforce_presets is set to TRUE * Any other param configuration will throw a 404 error. */