5093 Posts in 1516 Topics by 1113 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2066 Views |
-
Image resize on upload

3 April 2009 at 2:13pm
hi, I would like to resize image when user upload a image through cms. I have done my readings and tried to find relative post in the forum. The following is what i have found, but none of them actually solve my problem.
http://doc.silverstripe.com/doku.php?id=imageupload
http://doc.silverstripe.com/doku.php?id=gd
http://doc.silverstripe.com/doku.php?id=simpleimagefield
http://doc.silverstripe.com/doku.php?id=image&s=setwidthI follow the first article as it is very close to what I want, 'http://doc.silverstripe.com/doku.php?id=imageupload'. Yet something is off, and my script does not work. The following is what I have written.
class AboutUsPage extends Page {
static $db = array(
'Headline' => 'Varchar(255)'
);
static $has_one = array(
'AboutUsImage' => 'AboutUsPage_CustomeImage'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new TextField('Headline'), 'Content');
$fields->addFieldToTab("Root.Content.Images", new ImageField('AboutUsImage','Image'));
return $fields;
}
}class AboutUsPage_Controller extends Page_Controller {
}
class AboutUsPage_CustomeImage extends Image {
function genertateCustomeImage($gd){
return $gd->resizeByWidth(259);
}}
Could someone point me to the right direction please?
Thank you for taking your time to read this post!
-
Re: Image resize on upload

3 April 2009 at 2:21pm
I forgot to mention that, by doing so, the database is all linked correctly, I have record in File table that points to 'AboutUs' table, that's all good, only that image uploaded is not resized. what needs to be called in the template? I have tried following but it failed.
<img src="$AboutUsImage.CustomeImage.URL" />
-
Re: Image resize on upload

3 April 2009 at 9:17pm
Hi Silverfish
Try something like this;
<% control AboutUsImage %>
<% control CustomeImage %>
<img src="$URL" />
<% end_control %>
<% end_control %>or
<% control AboutUsImage %>
<img src="$CustomeImage.URL" />
<% end_control %> -
Re: Image resize on upload

6 April 2009 at 12:17pm
Hi aram
Thank you for the reply! It makes sense. However, it does not seem to work for me.
With the first method, it seems that <% control CustomeImage %> does not exist, if I remove this tag and end tag, the AboutUsImage shows.With second method, nothing is in the src.
I have double checked the file permission on the server and give 777 to the assets/ and its sub directories. Images appears to be stored in the 'File' table, and has ClassName of 'AboutUsPage_CustomeImage', but the image is in its original size.
-
Re: Image resize on upload

6 April 2009 at 12:54pm
Hi aram,
Quick correction. It worked.
The reason why it did not work in the first place is 'typo', I am very embarrassed, and sorry to waste anybody's time, especially aram.I revisited image class and thinking it should work, the 'defineMethods' should pick up my custom function, and then I noticed my misspelling, it is shown in my previous post, 'genertate'.
It is always at the back of my head, it should work, I had followed everything in the documentation, somehow I fear it would be something silly, and indeed, it was one of these days. Sorry guys. ^_^
| 2066 Views | ||
|
Page:
1
|
Go to Top |


