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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Get size of generated image after SetRatioSize


Go to End


4 Posts   2508 Views

Avatar
MrMuddy

Community Member, 13 Posts

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

Avatar
kevinlieb

Community Member, 4 Posts

20 August 2011 at 8:51am

I am having the same issue. Did you ever get a solution for this?

Avatar
UncleCheese

Forum Moderator, 4102 Posts

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

Avatar
DesignerX.com.au

Community Member, 107 Posts

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 :)