Jump to:

5453 Posts in 1674 Topics by 1198 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Adding multiple images to a page type

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2
Go to End
Author Topic: 6478 Views
  • BigChris
    Avatar
    Community Member
    63 Posts

    Re: Adding multiple images to a page type Link to this post

    Hello Ben_W,

    Thank you again for your help.

    $MyGalleryImage.SetSize(70,70) did not work under SilverStripe version 2.3.6 but does work under 2.4 beta.
    Version 2.3.6 throws up a missing argument 1, which I think I've traced back to the cache output of the template which is the SSView.
    In this the argument of (70, 70) does not appear to be part of the call to SetSize.

    I spent ages trying to get this to work, and may have to go with version 2.4. beta but its for a live site and I hope the stable version of 2.4 is around the corner.

    Cheers
    Chris

  • Usability Counts
    Avatar
    Community Member
    5 Posts

    Re: Adding multiple images to a page type Link to this post

    It's getting to the end of processing, but not uploading the image. What am I missing?

  • Ben_W
    Avatar
    Community Member
    79 Posts

    Re: Adding multiple images to a page type Link to this post

    BigChris, sorry mate, did not get any notification email from the post, until it's been bumped. for what it's worth. ^_^ You may try create your own image class like the following:

    class ImageGalleryPageImage extends DataObject {

    static $db = array(
    );
    static $has_one = array(
    'ParentImageGalleryPage' => 'ImageGalleryPage',
        'GalleryImage' => 'ImageGalleryPageImage_CustomImage',
        //'GalleryImage' => 'Image'
    );

    function getCMSFields_forPopup() {
    $fields = new FieldSet();
       
        $fields->push( new ImageField( 'GalleryImage', 'Gallery Image' ) );
        $fields->push( new LiteralField( 'literalfield_1', '<div>For best result, use image size of 930x500.</div><br>' ) );
       
    return $fields;
    }

    public function getTooltipThumbnail() {return $this->GalleryImage()->BackendThumbnail();}
    }

    class ImageGalleryPageImage_CustomImage extends Image {
       function generateCustomImage($gd){
          $gd->setQuality(85);
          return $gd->resizeRatio(930, 500);
       }
       function generateCustomThumbnailImage($gd){
          $gd->setQuality(85);
          return $gd->paddedResize(98, 66, '#000000');
       }
       function generateBackendThumbnail($gd){
          $gd->setQuality(85);
          return $gd->resizeRatio(300, 300);
       }
    }

    Please take a note that instead of using default class 'Image', just use your custom image class
    'GalleryImage' => 'ImageGalleryPageImage_CustomImage',
        //'GalleryImage' => 'Image'

    then in the ss template, you may use it like this:

    <% control ImageGalleryPageImages %>
    <li>
    <!--IMAGE-->
    <div class="thumbnail">
    <a href="$GalleryImage.CustomImage.URL" class="thumb">
                   <img src="$GalleryImage.CustomThumbnailImage.URL"<% if ImageTitle %> alt="$ImageTitle"<% end_if %> />
                </a>
    </div>
              <div class="caption"></div>
    <!--/IMAGE-->
    </li>
             <% end_control %>

    Hope it can still be useful, since we all need to maintain the old site. ^_^

  • liece
    Avatar
    Community Member
    9 Posts

    Re: Adding multiple images to a page type Link to this post

    @ BigChris

    For me, in 2.4,

    <% control GalleryImages %>
    $MyGalleryImage.CroppedImage(228,135)
    <% end_control %>

    worked perfectly. which was absolutely wonderful. I love SS! (this is my first SS project)

    6478 Views
Page: 1 2
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.