3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 701 Views |
-
Extending Image

31 March 2011 at 1:23am Last edited: 31 March 2011 8:37pm
I am trying to extend Image so when I return it to the template it has a certain compression ratio (don't ask):
CustomImage.php
class CustomImage extends Image
{
function generateOptimised($gd) {
$gd->setQuality(70);
return $gd->resizeByWidth(941);
}
}And in my template:
<% control CustomImage %>
$Optimised
<% end_control %>OR:
$CustomImage.Optimised
Doesn't do anything.
$CustomImage.Optimised.URL
returns 'http://' what am I doing wrong? have used custom images before
-
Re: Extending Image

31 March 2011 at 8:12am
My usual approach to extending Image is to use a DataObjectDecorator, just so the added methods are available on all Images. Though that may also require something like:
function Optimised() {
return $this->owner->getFormattedImage('Optimised');
}In your case, I would assume that the Image you're trying to use is a CustomImage, but just an ordinary Image.
-
Re: Extending Image

31 March 2011 at 8:29pm
Thanks simon_w works well and as you mentioned works on all images objects that is cool so now I can just make a bunch of different function in CustomImage and call them in my templates brilliant.
CustomImage.php
class CustomImage extends DataObjectDecorator
{
function Optimised($width, $height)
{
return $this->owner->getFormattedImage('Optimised', $width, $height);
}
function generateOptimised(GD $gd, $width, $height) {
$gd->setQuality(70);
return $gd->croppedResize($width, $height);
}
}_config.php
Object::add_extension('Image', 'CustomImage');
Template
$Image.Optimised(150,150)
| 701 Views | ||
|
Page:
1
|
Go to Top |

