21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2075 Views |
-
Solved :resizing image

12 March 2010 at 8:27pm Last edited: 16 March 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
-
Re: Solved :resizing image

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.
-
Re: Solved :resizing image

14 March 2010 at 6:19am Last edited: 14 March 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
-
Re: Solved :resizing image

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).
-
Re: Solved :resizing image

15 March 2010 at 4:43am Last edited: 16 March 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
| 2075 Views | ||
|
Page:
1
|
Go to Top |


