public function action_index($params) { if ($_GET) { $path = $params; $type = $_GET; } else { list($type, $path) = explode('/', $params); } foreach (Kohana::config("spot_image.folders") as $folder) { if (is_file($folder . $path)) { $file = $folder . $path; } } if (Kohana::config("spot_image.cache")) { // Check for cached image $cache_filename = Spot_Image::get_cache_filename($file, $type); if (file_exists(Kohana::config("spot_image.cache_directory") . $cache_filename)) { Spot_Image::get_from_cache(Kohana::config("spot_image.cache_directory") . $cache_filename); } else { Spot_Image::factory($file, $type); } } else { Spot_Image::factory($file, $type); } }
/** * Function that applies image_type * */ private function run() { $image = Image::factory($this->file); $image_params = (object) $this->image_params; // If width OR height is specified if (isset($image_params->width) or isset($image_params->height)) { $width = isset($image_params->width) ? $image_params->width : NULL; $height = isset($image_params->height) ? $image_params->height : NULL; if (isset($image_params->constraint)) { switch ($image_params->constraint) { case "none": $constraint = Image::NONE; break; case "minimal": if ($image->width / $image_params->width < $image->height / $image_params->height) { $constraint = Image::WIDTH; } else { $constraint = Image::HEIGHT; } break; case "width": $constraint = Image::WIDTH; break; case "height": $constraint = Image::HEIGHT; break; case "auto": $constraint = Image::AUTO; break; case "inverse": $constraint = Image::INVERSE; break; default: $constraint = Image::AUTO; break; } } else { $constraint = Image::AUTO; } if ($width < $image->width or $height < $image->height or Kohana::config("spot_image.allow_enlarge")) { $image->resize($width, $height, $constraint); } } // If crop_width OR crop_height is specified if (isset($image_params->crop_width) || isset($image_params->crop_height)) { $crop_width = isset($image_params->crop_width) ? $image_params->crop_width : NULL; $crop_height = isset($image_params->crop_height) ? $image_params->crop_height : NULL; $crop_x = isset($image_params->crop_x) ? $image_params->crop_x : NULL; $crop_y = isset($image_params->crop_y) ? $image_params->crop_y : NULL; $image->crop($crop_width, $crop_height, $crop_x, $crop_y); } // If rotate is specified if (isset($image_params->rotate)) { $image->rotate($image_params->rotate); } // If flip is specified if (isset($image_params->flip)) { if ($image_params->flip == "horizontal") { $direction = Image::HORIZONTAL; } if ($image_params->flip == "vertical") { $direction = Image::VERTICAL; } $image->flip($image_params->flip, $direction); } // If sharpen is specified if (isset($image_params->sharpen)) { $image->sharpen($image_params->sharpen); } $quality = isset($image_params->quality) ? $image_params->quality : 100; //create cache_filename $cache_filename = Spot_Image::get_cache_filename($this->file, $this->image_type); // Clear cache folder Spot_Image::clear_cache_folder(); // Save image to cache $image->save(Kohana::config("spot_image.cache_directory") . $cache_filename, $quality); // If the URL is expired set new expiration and render // if (Spot_Expires::check(Kohana::config("spot_image.browser_cache_expire")) === FALSE) // { // Spot_Expires::set(Kohana::config("spot_image.browser_cache_expire")); // } /*echo Kohana::debug($image_params); echo Kohana::debug($image); die();*/ // Render image Request::instance()->headers['Content-Type'] = File::mime_by_ext(pathinfo($this->file, PATHINFO_EXTENSION)); Request::instance()->response = $image->render(NULL, $quality); }