Jump to:

7939 Posts in 1472 Topics by 944 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » FLV.php CroppedImage trouble with custom thumbnail

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: 2076 Views
  • not2dumb
    Avatar
    Community Member
    16 Posts

    FLV.php CroppedImage trouble with custom thumbnail Link to this post

    hi uc,
    first of all my gratitude for this cool module. Solved me a lot of my problems, and i'm way beyond of beeing aware of all the possibilities given with this as i'm dealing with it only since a few days.

    now to my problem:
    i'm handling FLV's with your module wich works amazingly troublefree well. as there's no ffmpeg support on the webserver the site is hosted i've tried to deal with amanually uploaded jpeg 2 use as a videothumbnail. furthermore the presence of a thumbnail seems 2 be implicit 4 the VideoPopup function 2 work.
    so i've added an image field to my fieldset and changed the getThumbnail function in your FLV.php to this:

       public function getThumbnail()
       {
          if($thumbnailID = intval(DataObject::get_one("StartVideo", "AttachmentID = {intval($this->ID)}")->ThumbNailID))
          {
             $img = DataObject::get_by_id("Image", $thumbnailID);
             return $img;
          } else {
              if($img = DataObject::get_one("Image","Title = 'flv_thumb_{$this->ID}'")) {
              if(Director::fileExists($img->Filename))
                 return $img;
              return false;
              }
              return false;
           }
       }

    this works fine (as long as on thumnail image is uploaded)

    the only thing i cant get to work, is the CroppedImage thing in the VideoPopup function:

    ...
          return $this->customise(array(
             'PopupWidth' => $popup_width,
             'PopupHeight' => $popup_height,
             'Title' => $this->Title,
             'Link' => $this->FLVLink(),
             'Thumbnail' => $this->VideoThumbnail()//->CroppedImage($thumb_width, $thumb_height)
          ))->renderWith(array('FLVpopup'));
    ...

    as long as i comment out the cropping, all works perfect, if i do cropping NO images are rendered or displayed at all. and i don't have a clue why! as i haven't ffmpeg installed (yet) on my localhost, i've got no chance to compare db entry of the rendered image to the uploaded one. though i think there should'nt be any?!

    hope u can help on this strange issue!
    thanx

    btw, the problem with 4 arguments not workin with videopopup you mentioned in your youtube vid i solved this way:

       public function VideoPopup($sizeString)
       {
          $sizeData = explode(' ', $sizeString);
          if(isset($sizeData[0], $sizeData[1])){
             $thumb_width = intval($sizeData[0]);
             $thumb_height = intval($sizeData[1]);
          } else {
             $thumb_width = self::$default_thumbnail_width;
             $thumb_height = self::$default_thumbnail_height;
          }
          if(isset($sizeData[2], $sizeData[3])){
             $popup_width = intval($sizeData[2]);
             $popup_height = intval($sizeData[3]);
          } else {
             $popup_width = self::$default_popup_width;
             $popup_height = self::$default_popup_height;
          }
    ...

    i send the 4 attributes as ONE string, delimited by a "blank". maybe the code could be shortened or more elegant, but it works and i'm not too familiar with php.

  • UncleCheese
    Avatar
    4085 Posts

    Re: FLV.php CroppedImage trouble with custom thumbnail Link to this post

    When you say the CroppedImage function "doesn't work" could you describe what it is or is not doing?

  • not2dumb
    Avatar
    Community Member
    16 Posts

    Re: FLV.php CroppedImage trouble with custom thumbnail Link to this post

    ok,
    all this text but the most important i forgot:

    there is no errormessage or whatever, the function does'nt return an image.
    in the generated html the link for shadowbox is there but no <img> tag inside the <a> tag - so the link isn't even visible in the browser.

    hope that was clear?

  • UncleCheese
    Avatar
    4085 Posts

    Re: FLV.php CroppedImage trouble with custom thumbnail Link to this post

    Is the image being stored with the title "flv_thumb_{$ID}" as seen in the getThumbnail() function?

  • not2dumb
    Avatar
    Community Member
    16 Posts

    Re: FLV.php CroppedImage trouble with custom thumbnail Link to this post

    no, it is'nt.

    i thought the CroppedImage function is controlled by the Image class, and therefore the filename of the customthumbnail is free to choose.
    so the thumbnail file has to be stored according the given pattern for CroppedImage to work?

    seems i've overseen something...??

    i prefer understanding to believing, can u tell me why the filename is compulsive?

    thanx a lot

  • UncleCheese
    Avatar
    4085 Posts

    Re: FLV.php CroppedImage trouble with custom thumbnail Link to this post

    Sure. This was a tricky decision. If the FLV class used a normalized data model with a has_one relation to the Image class, it would create the need for an FLV table. I liked the idea of DataObjectManager having a small footprint, with no tables. For the 99% of users who are not going to take advantage of the Video/Audio features, it would seem weird for them to have to look at an FLV table in their database. The alternative was to decorate the File object with a has_one Thumbail, but that didn't make much sense either, so I figured if the FLV class has total control of the creation and deployment of the thumbnails, then a naming convention would hold up pretty well.

    Until someone goes and tries something like this.

    So get FFMPEG!

  • not2dumb
    Avatar
    Community Member
    16 Posts

    Re: FLV.php CroppedImage trouble with custom thumbnail Link to this post

    yep, this someone is me

    ok, i think i'll manage this also. now that i know what causes the failure. i think i'll complete the function by copying the custom thumbnail to a new file with the proper filename according your given pattern - should'nt be 2 tricky.

    if u like, i'll post the code here as i may be helpful for others, who have the same problem:
    willing to get all out of your stupefying modules!

    as the webhost is not willing (at the moment) to install ffmpeg on their server(s), i have to cope with this custom solution...

    thank yout for your help and your great work!

    cheers

  • not2dumb
    Avatar
    Community Member
    16 Posts

    Re: FLV.php CroppedImage trouble with custom thumbnail Link to this post

    hi uncle cheese,
    this is how i changed the getThumbnail function:

       public function getThumbnail()
       {
          if($thumbnailID = intval(DataObject::get_one("StartVideo", "AttachmentID = {intval($this->ID)}")->ThumbNailID))
          {
             $updTitle = "UPDATE File SET Title='flv_thumb_".$this->ID."' WHERE ID=".$thumbnailID;
             DB::query($updTitle);
             return($img = DataObject::get_by_id("Image", $thumbnailID));
          } else {
              if($img = DataObject::get_one("Image","Title = 'flv_thumb_{$this->ID}'")) {
              if(Director::fileExists($img->Filename))
                 return $img;
              return false;
              }
              return false;
           }
       }

    does the custom thumbnail trick perfectly

    cheeers

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