Hi there, I wrote a nice extension to the Image Object, which allows me to merge Images together, or blur them (by a gaussian algorithm), or also set the Backgroundcolor on a SetSize Method. (will put it on Github soon)
What I now was missing was the ability, to chain the methods.
Like, I want to resize an Image and blur it (to make a small Preview).
The Method Looks like this:
$MyObject->FullImage()->SetWidth(150)->Blur()
To achieve this, there is a small Piece of Code that needs to be added to the Image.php File.
Here is the original Code:
/**
* Return an image object representing the image in the given format.
* This image will be generated using generateFormattedImage().
* The generated image is cached, to flush the cache append ?flush=1 to your URL.
* @param string $format The name of the format.
* @param string $arg1 An argument to pass to the generate function.
* @param string $arg2 A second argument to pass to the generate function.
* @return Image_Cached
*/
function getFormattedImage($format, $arg1 = null, $arg2 = null) {
if($this->ID && $this->Filename && Director::fileExists($this->Filename)) {
$cacheFile = $this->cacheFilename($format, $arg1, $arg2);
if(!file_exists(Director::baseFolder()."/".$cacheFile) || isset($_GET['flush'])) {
$this->generateFormattedImage($format, $arg1, $arg2);
}
$cached = new Image_Cached($cacheFile);
// Pass through the title so the templates can use it
$cached->Title = $this->Title;
return $cached;
}
}
and Here are the Lines for ParentID and ID added, to make chaining available.
function getFormattedImage($format, $arg1 = null, $arg2 = null) {
if($this->ID && $this->Filename && Director::fileExists($this->Filename)) {
$cacheFile = $this->cacheFilename($format, $arg1, $arg2);
if(!file_exists(Director::baseFolder()."/".$cacheFile) || isset($_GET['flush'])) {
$this->generateFormattedImage($format, $arg1, $arg2);
}
$cached = new Image_Cached($cacheFile);
// Pass through the title so the templates can use it
$cached->Title = $this->Title;
$cached->ID = $this->ID;
$cached->ParentID = $this->ParentID;
return $cached;
}
}
Is it possible, to add this to the Framework (in my case it's still 2.4.x) permanently?
Regards
Andre