21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2039 Views |
-
Custom Image Resize in DataObject

22 August 2009 at 4:26pm Last edited: 22 August 2009 4:27pm
Hello I have a problem I could not do a resize a photo already investigated but failed to
this is my codeGaleria.php
--------------------------------------------class Galeria extends DataObject {
static $db = array ('Titulo' => 'Varchar', 'Desc' => 'HTMLText' );
static $has_one = array ('GaleriaPage' => 'GaleriaPage', 'Image' => 'Image' );
public function getCMSFields_forPopup() {
$fields = new FieldSet ( new TextField ( 'Titulo' ), new HtmlEditorField ( 'Desc' ), new ImageField ( 'Image' ) );
return $fields;
}}
--------------------------------------------Galeria.php
--------------------------------------------class GaleriaPage extends Page {
static $has_many = array(
'Galerias' => 'Galeria',
);
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Galeria',
new DataObjectManager(
$this,
'Galerias',
'Galeria',
array('Imagen' => 'Imagen', 'Titulo' => 'Titulo','Desc' => 'Descripcion'),
'getCMSFields_forPopup'
));
return $fields;
}
}class GaleriaPage_Controller extends Page_Controller {
function init() {
parent::init();
Requirements::css('jsparty/Slideshow2/css/slideshow.css');
Requirements::javascript('themes/mtac/js/mootools.js');
Requirements::javascript('themes/mtac/js/slideshow.js');
Requirements::javascript('themes/mtac/js/slideshow.kenburns.js');
}function Galery() {
$reviewContent = DataObject::get("Galeria","GaleriaPageID =" . $this->ID);
// Debug::show($reviewContent);
return $reviewContent;
}function ImgResize($gd) {
return $gd->resize(50,50)->URL();
}}
--------------------------------------------GaleriaPage.ss
--------------------------------------------....
<script>
var data = {
<% control Galery %>
'$Image.URL': {
caption: '$Titulo',
thumbnail: '$Image.ImgResize'
<% if Last %> } <% else %> }, <% end_if %>
<% end_control %>
};
</script>
....
--------------------------------------------thanks in advance for helping
-
Re: Custom Image Resize in DataObject

22 August 2009 at 10:55pm
Hi wardog,
I'm not entirely sure what you are trying to do. If you just want to echo a resized image in the template, then you should be able to do this without your ImgResize function.
If you need to resize in the PHP with a custom function (like you are trying to do now) then your function is wrong.
Use (in you're 'Galeria' class):
function myResize($width = 50, $height = 50) {
return $this->Image()->getFormattedImage('resizeRatio',$width,$height);
}You should then be able to use 'myResize' as a control in the SS template.
That should sort out your problem.
-
Re: Custom Image Resize in DataObject

23 August 2009 at 5:41pm
I think I did not understand very well .. I am making a template to create a gallery using slidershow
but I can not do resize the image to the thumb ... and I read the documentation but I can only do when DataObject use or do not understand how to make the image resize what you need so as it is generating resize the image and get the url of the image with the display so that it can resize -
Re: Custom Image Resize in DataObject

23 August 2009 at 6:12pm Last edited: 23 August 2009 6:12pm
ok I've solved. anyway thank you very much for the help
<% control Galery %>
'$Image.Link': {
caption: '$Titulo',
<% control Image %>
<% control ResizedImage(50,50) %>
thumbnail: '$URL'
<% end_control %>
<% end_control %>
<% if Last %> } <% else %> }, <% end_if %>
<% end_control %>
};
</script>
| 2039 Views | ||
|
Page:
1
|
Go to Top |

