Skip to content

Instantly share code, notes, and snippets.

@xwero
Created March 31, 2011 08:07
Show Gist options
  • Save xwero/896011 to your computer and use it in GitHub Desktop.
Save xwero/896011 to your computer and use it in GitHub Desktop.
Process image before generating the tag
<?php defined('SYSPATH') or die('No direct script access.');
class HTML extends Kohana_HTML{
/**
* Process image before creating tag
*
* @param string $file master file
* @param string $processed_file file to display
* @param array $attributes with extra processing attributes
* @param type $index
* @return string
*/
public static function pimage($file, $processed_file, array $attributes, $index = FALSE)
{
if(Arr::get(Kohana::modules,'image'))
{
throw new Kohana_Exception('Activate the Image module');
}
$image = Image::factory($file, Arr::get($attributes, 'driver'));
unset($attributes['driver']);
$refection = new ReflectionClass('Image');
$image_actions = array();
foreach($refection->getMethods(ReflectionMethod::IS_PUBLIC) as $method)
{
if(isset($attributes[$method->name]))
{
$image_actions[] = array('method'=>$method,'arguments'=>$attributes[$method->name]);
unset($attributes[$method->name]);
}
}
if(!is_file(realpath($processed_file)))
{
foreach($image_actions as $action) {
$action['method']->invokeArgs($image,$action['arguments']);
}
$image->save($processed_file, Arr::get($attributes, 'save_quality', 100));
unset($attributes['save_quality']);
}
return HTML::image($processed_file, $attributes, $index);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment