Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

gd image resize?

Go to End

5 Posts   2656 Views


Community Member, 13 Posts

14 May 2008 at 7:06pm

Edited: 14/05/2008 7:23pm


i went through this tutorial covering image resizing. i initially tried modifying it to work within a dataObject, but when that failed i went back and copied it word for word to no avail.

from what i can gather it seems the BannerImage isn't getting created at all. at least when i look in the assets folder i can other resampled images, CMSThumbnail and a few SetWidth/ResizedImage versions too.

i'm guessing it's something really small, and really dumb that i've overlooked.

class Page extends SiteTree {
	static $db = array(
		'featuredTitle' => 'Text'
	static $has_one = array(
		'BannerImage' => 'Image'
	function getCMSFields() {
		$fields = parent::getCMSFields();
		$fields->addFieldToTab('Root.Content.Main', new TextField('featuredTitle','Headline'));
		$fields->addFieldToTab('Root.Content.MyBannerImage', new ImageField('BannerImage','Featured Image'));
		return $fields;

class Page_Controller extends ContentController {
	function init() {

class Page_BannerImage extends Image {

	function generatePageBanner($gd) {
		return $gd->paddedResize(619,154);


in i have

<% if BannerImage.PageBanner %>
 <img class="headerImage" src="$BannerImage.PageBanner.URL" alt="Header banner" />
<% else %>
 <% control Page(home) %>
  <img class="headerImage" src="$BannerImage.PageBanner.URL" alt="Header banner" />
 <% end_control %>
<% end_if %>

thanks in advance


Forum Moderator, 5523 Posts

14 May 2008 at 11:29pm

I think it might be failing on $BannerImage.PageBanner.URL. I dont know if it supports this or not. Try

<% control BannerImage %>
<% end_control %>

Also make sure the image is actually saving in the DB. Check BannerImageID exists in the Page table. then take that ID and look on the File table to make sure theres a file with that ID


Community Member, 13 Posts

15 May 2008 at 12:53pm

hi willr

thanks for your reply. it does seem that the database record isn't getting created. i tried adding a field to the $has_one array called PageBanner, but it doesn't auto associate the ID. this has been moved to a low priority as i've fallen back on the setWidth() method which is functioning fine for now.

i would in the future like to understand more about extending the image class. so if anyone has experience with it, i'd appreciate any pointers.



Community Member, 3 Posts

17 June 2008 at 9:52am

Something I learnt the other day is that the field you create in the $has_one array has to use the extended image class. For you, you need to change "Image" to "Page_BannerImage".



Community Member, 11 Posts

2 September 2008 at 5:05am

Thank you very much Danger. Now it works fine.
so long BerT