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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

how to reuse images from image gallery?


Reply


5 Posts   1431 Views

Avatar
theAlien

Community Member, 131 Posts

28 May 2009 at 12:16pm

Edited: 28/05/2009 12:22pm

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();
   }
}

Avatar
UncleCheese

Forum Moderator, 4096 Posts

30 May 2009 at 2:57am

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

Avatar
theAlien

Community Member, 131 Posts

17 July 2009 at 3:09pm

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: [url=http://silverstripe.org/dataobjectmanager-module-forum/show/261417#post261417]how can I reuse images from the image gallery[/url]

Avatar
UncleCheese

Forum Moderator, 4096 Posts

18 July 2009 at 2:08am

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

MyImageGalleryPage extends ImageGalleryPage

$itemClass = "MyImageGalleryItem";

MyImageGalleryItem extends ImageGalleryItem

Avatar
theAlien

Community Member, 131 Posts

18 July 2009 at 2:46am

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