I'm writing a function that selects an image at random and returns an image tag. I'd like to scale that image, but I can't work out how.
class HomePage_Controller extends Page_Controller {
...
function RandomImage() {
$galleryItem = DataObject::get_one('GalleryItem', 'MyHomePageID != 0', false, 'RAND()');
$g = DataObject::get_by_id("GalleryItem_ProductImage", $galleryItem->GalleryItemImageID);
//somehow scale $g here
return "<img src=\"$g->Filename\" alt=\"$galleryItem->GalleryItemTitle\" />";
}
...
}
As I understand it, my get_by_id() call should be returning an Image (GalleryItem_ProductImage extends Image) which means that I should be able to use GD functions on it.
But if I create a new GD object and use resize() it, how do I then get the filename for the src attribute?