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

FLV.php CroppedImage trouble with custom thumbnail


Reply

8 Posts   2172 Views

Avatar
not2dumb

23 July 2009 at 9:46am Community Member, 16 Posts

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.

Avatar
UncleCheese

24 July 2009 at 1:08am 4085 Posts

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

Avatar
not2dumb

24 July 2009 at 1:37am Community Member, 16 Posts

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? :-)

Avatar
UncleCheese

24 July 2009 at 2:28am 4085 Posts

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

Avatar
not2dumb

24 July 2009 at 6:03am Community Member, 16 Posts

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

Avatar
UncleCheese

24 July 2009 at 7:42am 4085 Posts

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!

Avatar
not2dumb

24 July 2009 at 7:57am Community Member, 16 Posts

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

Avatar
not2dumb

24 July 2009 at 5:19pm Community Member, 16 Posts

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