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:

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Solved :resizing image


Go to End


6 Posts   3024 Views

Avatar
Rishi

Community Member, 97 Posts

12 March 2010 at 8:27pm

Edited: 16/03/2010 7:52pm

i have created a page type where i am uploading an image and i am displaying it on the page but i need to resize the image not cropped because when i am croping it cropped the image in ratio which sometime result n a very bad image so i just want to resize the image not crop my code so far is

php page
<?php
class ProfilePage extends Page {
static $db = array(
);
static $has_one = array(
'Photo' => 'Image'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Images", new ImageField('Photo'));
return $fields;
}

static $defaults = array(
'ShowInMenus' => false
);

}

class ProfilePage_Controller extends Page_Controller {

}
?>

template page

<% control Photo %>
<% control CroppedImage(540,340) %>
<img src ="$URL" alt="" />
<% end_control %>
<% end_control %>

thank you in advance

Avatar
Willr

Forum Moderator, 5523 Posts

13 March 2010 at 2:35pm

Well if you don't want to crop the image then perhaps use something like PaddedImage() or SetSize which doesn't crop the image.

You can see a list of what you can use on http://doc.silverstripe.org/doku.php?id=image#resizing_in_templates.

Avatar
Rishi

Community Member, 97 Posts

14 March 2010 at 6:19am

Edited: 14/03/2010 8:51pm

thanks a lot Willr
this is the document i was looking for .you have saved me thanks once again but i have encountered few problem on implementing the functions.

1. when i am calling the picture as simple variable it is showing up
code

$Photo

2.when I am calling it with SetWidth(80) it is working fine

code
$Photo.SetWidth(80)

3.but when i am calling it using SetSize(80,80) it is giving me error as

Missing argument 1 for Image::SetSize()
the code i have tried are

$Photo.SetSize(80 , 80)
$Photo.SetSize(80, 80)
$Photo.SetSize(80,80)

nothing is working

4.when i am calling it as PaddedImage(80, 80) i am getting this error

imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions

the code i have tried are
$Photo.PaddedImage(80, 80)
$Photo.PaddedImage(80,80)
$Photo.PaddedImage(80 , 80)

Thank you in advance

Avatar
Rishi

Community Member, 97 Posts

14 March 2010 at 8:53pm

Please help me out in this

Avatar
Willr

Forum Moderator, 5523 Posts

14 March 2010 at 9:10pm

Try <% control Photo %>$PaddedImage(80,80)<% end_control %> or even <% control Photo %><% control PaddedImage(80, 80) %>$URL<% end_control %><% end_control %> and see if either of those work (The template parser is a bit hit and miss like this).

Avatar
Rishi

Community Member, 97 Posts

15 March 2010 at 4:43am

Edited: 16/03/2010 7:51pm

Thank you.. the below code works great for me

<% control Photo %><% control PaddedImage(80, 80) %>$URL<% end_control %><% end_control %>
thank a lot