7919 Posts in 1358 Topics by 932 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Get size of generated image after SetRatioSize
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 983 Views |
-
Get size of generated image after SetRatioSize

4 March 2011 at 2:54am
Hi All,
I have a very simple gallery page set up using a DataObject.... it allows me to upload multiple images to a single page on my site.
Here are the relevant files :
/mysite/code/galleryImages.php
class galleryImages extends DataObject {
static $db = array(
'Title' => 'Text'
);
static $has_one = array(
'Image' => 'Image',
'GalleryPage' => 'GalleryPage'
);public function getCMSFields_forPopup() {
return new FieldSet(
new TextField('Title'),
new FileIFrameField('Image')
);
}}
/mysite/code/GalleryPage.php
class GalleryPage extends Page {
static $has_many = array(
'Images' => 'galleryImages'
);
public static $db = array(
);
public static $has_one = array(
);public function getCMSFields() {
$f = parent::getCMSFields();
$manager = new ImageDataObjectManager(
$this,
'Images',
'galleryImages',
'Image',
array(
'Title' => 'Title'
),
'getCMSFields_forPopup');
$f->addFieldToTab("Root.Content.Gallery", $manager);return $f;
}}
class GalleryPage_Controller extends Page_Controller {
}
and a snippet from /themes/..../GalleryPage.ss
<div id="gallerySlider">
<% control Images %>
<a class="gallerythumb" href="$Image.URL" title="$Caption">$Image.SetRatioSize(120,110)</a>
<% end_control %>
</div>Now... all of the above is working well... I can upload and re-order the images in the CMS, etc. and they get displayed properly in the template. The real question... is there any way to get the *actual* width of the thumbnail images which are being created using SetRatioSize() ? The reason being that I need to put some inline styling into the page (i.e. <img style="width: blah;" src="" />)
Any ideas ?
Cheers all
Tim
-
Re: Get size of generated image after SetRatioSize

20 August 2011 at 8:51am
I am having the same issue. Did you ever get a solution for this?
-
Re: Get size of generated image after SetRatioSize

20 August 2011 at 2:43pm
Just change the scope to the resize function, and you'll get the new dimensions.
<% control Images %>
<a class="gallerythumb" title="$Caption" href="$image.URL">
<% control Image %>
<% control SetRatioSize(210,110) %>
<img src="URL" width="$Width" height="$Height" />
<% end_control %>
<% end_control %></a>
<% end_control %>---------------
Silverstripe tips, tutorials, screencasts, and more. http://www.leftandmain.com -
Re: Get size of generated image after SetRatioSize

20 August 2011 at 3:53pm
woow.. ty so much.... i am collection all snipets from around SilverStripe & soon making a blog, it will explain these small thing in more details & makes it easier to find.. Cheese man .. o i mean Cheers man
| 983 Views | ||
|
Page:
1
|
Go to Top |



