Hi,
I'm a bit confused. I want to create a new resize function that I can call from the template. According to a recipe I added this to mysite/Page.php :
class Page extends SiteTree
...
static $has_one = array(
'Image' => 'Page_Image' // We define Page_Image, which is a subclass of Image
);
...
}
Then I added a custom function, also to mysite/Page.php
class Page_Image extends Image { // This class can go inside the same file as Page.php
function generatePaddedImageByWidth($gd) {
$height = $gd->getHeight;
return $gd->paddedResize(500, $height);
}
}
The function creates a padded image with a maximum width, but keeps the original image height (it basically creates an image that is horizontally centered with white padding on the left and on the right).
Unfortunately it doesn't work. But if I put the following into /sapphire/core/model/Image.php it works well:
function generatePaddedImageByWidth(GD $gd, $width) {
$height = $gd->getHeight();
return $gd->paddedResize($width, $height);
}
I would just prefer not to change core code but keep changes in Page.php. Any hint is highly appreciated.
Cheers!
Anatol