Jump to:

7935 Posts in 1536 Topics by 943 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, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1268 Views
  • MrMuddy
    Avatar
    Community Member
    13 Posts

    Get size of generated image after SetRatioSize Link to this post

    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

  • kevinlieb
    Avatar
    Community Member
    4 Posts

    Re: Get size of generated image after SetRatioSize Link to this post

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

  • UncleCheese
    Avatar
    4085 Posts

    Re: Get size of generated image after SetRatioSize Link to this post

    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

  • DesignerX.com.au
    Avatar
    Community Member
    107 Posts

    Re: Get size of generated image after SetRatioSize Link to this post

    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

    1268 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.