Jump to:

7940 Posts in 1543 Topics by 946 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » how to reuse images from image gallery?

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: 1359 Views
  • theAlien
    Avatar
    Community Member
    131 Posts

    how to reuse images from image gallery? Link to this post

    How can I reuse images from the image gallery?

    FYI: I'm having a header with several images that I can set with ImageFields.
    These images are set with a Page_Image extends Image class (see code below).
    The images in ImageGallery are set with ImageGalleryImage extends Image (see code below).

    This way the two conflict: If I use an ImageGallery image in the header, the image won't show up in the gallery. If I use a header image in an album, it gets even transfered from the folder all headerimages are stored in to the specific folder of the album. And off course it won't show up in the header anymore.

    That isn't that big a problem, if at least I could get the image from the albumfolder show up both in the header and the album.

    from page.php
    class Page_Image extends Image {
       public function generateMainImage($gd) {
          $gd->setQuality(100);
          return $gd->croppedResize(400,232);
       }
       public function generateSubImage($gd) {
          $gd->setQuality(100);
          return $gd->croppedResize(180,140);
       }
       public function generateBGImage($gd) {
          $gd->setQuality(100);
          return $gd->resizeByWidth(801);
       }
    }


    from ImageGalleryImage.php
    class ImageGalleryImage extends Image
    {
       public function generateRotateClockwise(GD $gd)
       {
          return $gd->rotate(90);
       }
       public function generateRotateCounterClockwise(GD $gd)
       {
          return $gd->rotate(270);
       }
       public function clearResampledImages()
       {
          $files = glob(Director::baseFolder().'/'.$this->Parent()->Filename."_resampled/*-$this->Name");
           foreach($files as $file) {unlink($file);}
       }
       public function Landscape()
       {
          return $this->getWidth() > $this->getHeight();
       }
       public function Portrait()
       {
          return $this->getWidth() < $this->getHeight();
       }
    }

  • UncleCheese
    Avatar
    4085 Posts

    Re: how to reuse images from image gallery? Link to this post

    Why can't you just do a $has_one ImageGalleryImage on your page object?

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: how to reuse images from image gallery? Link to this post

    Pretty old post, but I changed my focus to some other subjects. Right now, I'm (also) back at this one:

    Unfortunately this is not possible. Because I want some resizing on the images, I would have to redeclare ImageGalleryImage, which isn't possible (error: cannot redeclare ImageGalleryImage).

    Of course I could do the resizing in the template, but I would rather not to: I like my templates as clean as possible (and also I have some suspicions that resizing in the template will slow the template down - I'm not sure about that though).

    So the question still is: how can I reuse images from the image gallery

  • UncleCheese
    Avatar
    4085 Posts

    Re: how to reuse images from image gallery? Link to this post

    You don't need to redeclare the class. You can just sub it out.

    MyImageGalleryPage extends ImageGalleryPage

    $itemClass = "MyImageGalleryItem";

    MyImageGalleryItem extends ImageGalleryItem

  • theAlien
    Avatar
    Community Member
    131 Posts

    Re: how to reuse images from image gallery? Link to this post

    And again I´m amazed by the power and flexibility of SS in general and your modules in particular...
    Thanks

    1359 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.