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

PaddedResize in controller?


Go to End


2 Posts   1557 Views

Avatar
nekranox

Community Member, 31 Posts

23 November 2011 at 1:38am

Hey guys,

I am currently using $image->SetWidth inside one of my PHP controllers but would like to use the same functionality that's provided by $Image.PaddedResize in the template. I couldn't find a PaddedResize method in Image.php.

The closest I found was generateFormattedImage() which looks like it can access internal functions that might provide a padded resize. I couldn't get it to return anything sensible.

Any ideas? Thanks,

Robbie

---
code for reference:

	public function LoadMainImages() {
		$images = DataObject::get('GalleryImage', 'GalleryImage.'.$this->ClassName.'ID='.$this->ID);
		$output = new DataObjectSet();
		foreach($images as $image) {
			$image->ImageFile = DataObject::get('File', 'File.ID='.$image->ImageFileID)->items;
			$image->ImageFile = $image->ImageFile[0]->SetWidth($this->MainImageWidth, $this->MainImageHeight);
			$image->ResizedImage = $image->ImageFile->record['Filename'];
			$output->push($image);
		}
		return $output;
	}

Avatar
pac

Community Member, 25 Posts

29 November 2011 at 5:36am

$Image.PaddedImage(80, 80)
can use a 3rd argument with the Hex background color I think