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.

Template Questions /

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

pick image size in cms and crop the image to it in the template


Go to End


2 Posts   1414 Views

Avatar
luuk

Community Member, 15 Posts

24 June 2014 at 9:35pm

Edited: 24/06/2014 10:40pm

Hi,

I would like to build a functionality that gives the user the option to pick a image width and heigt, or for example (small, medium and large) and use these values in my template to crop the image to te specified size.

I have absolutely no clue on how to do this and als haven't found anything on the internet yet.

Does someone know if this is possible and how to do it? Basically it should be a croppedImage function which support variable input.

Thanks in advance.

Avatar
gened

Community Member, 10 Posts

30 July 2014 at 10:34pm

Edited: 30/07/2014 10:34pm

There a few ways to approach this. Heres one

class UserImage extends Image {

private static $db = array(
'UserHeight' => 'Int',
'UserWidth' => 'Int
);

public function CroppedUserImage(){
return $this->CroppedImage($this->UserHeight, $this->UserWidth);
}
}

Then in a template

<% loop UserImages %>
$CroppedUserImage
<% end_loop %>