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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Operations on Image Objects


Go to End


3 Posts   1412 Views

Avatar
nekranox

Community Member, 31 Posts

14 July 2010 at 1:20am

Hey guys,

I want to perform paddedResize on an image object, I think I've sub-classed the image class correctly but the edited image isn't coming through into the template. Would really appreciate it if someone could have a quick look at this for me:

ContractsPage.php:

class ContractPage extends Page {

	
	static $singular_name = 'Contract';
	static $allowed_children = 'none';
	static $can_be_root = false;	
	
	public static $db = array(
		"start" => "Varchar(50)",
		"end" => "Varchar(50)",
		"Type" => "Varchar(20)",
	);

	 static $has_one = array(
	   'Logo' => 'ContractPage_ResizedImage'
	 );

	function getCMSFields() {
	
		$typeOptions = array(
		  'Project Management' => 'Project Management',
		  'Business Support' => 'Business Support',
		);
	
		$fields = parent::getCMSFields();
	  	$fields->addFieldToTab('Root.Content.Main', new DropdownField('Type', 'Type', $typeOptions));	
		$fields->addFieldToTab('Root.Content.Main', new DateField('start', 'Start Date'));
		$fields->addFieldToTab('Root.Content.Main', new DateField('end', 'End Date'));		
		$fields->addFieldToTab('Root.Content.Main', new ImageField("Logo"));		
		return $fields;
	}
}

class ContractPage_Controller extends Page_Controller {

}

class ContractPage_ResizedImage extends Image {

   function generateResizedImage($gd) {
   
      $gd->setQuality(100);
      return $gd->paddedResize(100,83);
   }

}

Includes\Contracts.ss:

<% if URLSegment != contracts  %>


<div id="contractsTitleBox">
	<% control ContractPage_ResizedImage %>
	$Logo.ResizedImage.URL
    <% end_control %>
	
    <h2>$Title</h2>
...

Avatar
swaiba

Forum Moderator, 1899 Posts

14 July 2010 at 1:36am

Hi,

this might help... resizing the image on the template without the extra code in the controller...

<% control DataObjectSetOfImages %>
	<% control ImageDataObject %>
		<% control PaddedImage(100,83) %>
		<% end_control %>
	<% end_control %>
<% end_control %>

Barry

Avatar
TotalNet

Community Member, 181 Posts

14 July 2010 at 9:48am

Hi,

I don't think you need the control (control ContractPage_ResizedImage)

You should be able to call $Logo.ResizedImage.URL

hth

Rich