Added new watermarkAlignment option and added full path or URL support to image.
authorAlan Jack Pippin <ajp@pippin.(none)>
Fri, 19 Oct 2007 05:35:25 +0000 (23:35 -0600)
committerAlan J. Pippin <ajp@pippins.net>
Fri, 19 Oct 2007 05:35:25 +0000 (23:35 -0600)
ItemAddEmbedVideo.inc
templates/EmbedVideoSiteAdmin.tpl

index 03a54e94d31d5b2b68e911c9d0ce04c9c6f97c49..4e517acb19a0214542a31360beb9b4d74f835ed1 100644 (file)
@@ -70,7 +70,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
           global $debugOutput, $useInternalFlvPlayer, $youtubeDevId;
           global $width, $height, $externalFlvPlayer, $externalFlvPlayerVars;
           global $flvThumbnail, $useRemoteSize, $autoStart;
-          global $watermarkVideos, $watermarkImage;
+          global $watermarkVideos, $watermarkImage, $watermarkAlignment;
 
           /* Find out what value our parameters should have by looking to see if they
             * are defined in our overrides section or default section. If they are not
@@ -89,6 +89,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
           $autoStart = $this->getParameter($ItemAddEmbedVideo, 'autoStart', "false");
           $watermarkImage = $this->getParameter($ItemAddEmbedVideo, 'watermarkImage', "");
           $watermarkVideos = $this->getParameter($ItemAddEmbedVideo, 'watermarkVideos', "false");
+          $watermarkAlignment = $this->getParameter($ItemAddEmbedVideo, 'watermarkAlignment', "center");
 
           /* Print our stored/set Parameters */
           if(!strcmp($debugOutput,"true")) {
@@ -107,6 +108,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
             print "autoStart=$autoStart<br>";
             print "watermarkVideos=$watermarkVideos<br>";
             print "watermarkImage=$watermarkImage<br>";
+            print "watermarkAlignment=$watermarkAlignment<br>";
             print "<hr>";
           }
 
@@ -661,31 +663,41 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
             } else {
               $watermarkImage = $gallery2_url.$gallery2_video_watermark;
             }
-
+            
             /* Get the watermark Image Extension */
             preg_match('/\.(...)$/', $watermarkImage, $matches);
             $watermarkExt=$matches[1];
             
             /*
              * Check to make sure the URL to the watermark image file is valid
-             * (That the file exists at the URL given)
+             * (That the file exists at the URL given). Skip this part if it is a local path.
              */
-            list ($successfullyCopied, $response, $headers) =
-              $this->fetchWebFileHeaders($watermarkImage, $extraHeaders);
-            if (!$successfullyCopied) {
-              return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
-                           "Unable to find the watermark image at url: $watermarkImage - $response"),NULL,NULL);
-            }
+            if(!preg_match("/^\//", $watermarkImage)) {
+              list ($successfullyCopied, $response, $headers) =
+                $this->fetchWebFileHeaders($watermarkImage, $extraHeaders);
+              if (!$successfullyCopied) {
+                return array(GalleryCoreApi::error(ERROR_BAD_PATH,__FILE__,__LINE__,
+                       "Unable to find the watermark image at url: $watermarkImage - $response"),NULL,NULL);
+              }
             
-            /* Download the watermark image to a local file */
-            $tmpDir = $gallery->getConfig('data.gallery.tmp');
-            $watermark = $platform->tempnam($tmpDir, 'wmk_img_');
-            $watermark.= "." . $watermarkExt;
-            list ($successfullyCopied, $response, $headers) =
-              GalleryCoreApi::fetchWebFile($watermarkImage, $watermark, $extraHeaders);
-            if (!$successfullyCopied) {
-              return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
-                           "Unable to copy watermark image from url: $watermarkImage - $response"),null,null);
+              /* Download the watermark image to a local file */
+              $tmpDir = $gallery->getConfig('data.gallery.tmp');
+              $watermark = $platform->tempnam($tmpDir, 'wmk_img_');
+              $watermark.= "." . $watermarkExt;
+              list ($successfullyCopied, $response, $headers) =
+                GalleryCoreApi::fetchWebFile($watermarkImage, $watermark, $extraHeaders);
+              if (!$successfullyCopied) {
+                return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+                       "Unable to copy watermark image from url: $watermarkImage - $response"),null,null);
+              }
+            } else {
+              $tmpDir = $gallery->getConfig('data.gallery.tmp');
+              $watermark = $platform->tempnam($tmpDir, 'wmk_img_');
+              $watermark.= "." . $watermarkExt;
+              if(!$platform->copy($watermarkImage, $watermark)) {
+                return array(GalleryCoreApi::error(ERROR_STORAGE_FAILURE,__FILE__,__LINE__,
+                       "Unable to copy watermark image from path: $watermarkImage"),null,null);
+              }
             }
             
             /* See if there is a toolkit installed that can perform a composite operation */
@@ -726,8 +738,9 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
             /* This has to be done to satisfy the argument requirement for the toolkit operation */
             $dataDir = $gallery->getConfig('data.gallery.base');
             $dataDir=preg_replace("/\//","\\/",$dataDir);
-            preg_match("/$dataDir(.*)/", $watermark, $matches);
-            $watermark = $matches[1];
+            if(preg_match("/$dataDir(.*)/", $watermark, $matches)) { 
+              $watermark = $matches[1];
+            }
             
             /* General debug output */
             if(!strcmp($debugOutput,"true")) {
@@ -747,7 +760,7 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
                                                                 $mimeType, 'composite', $newTmpFile, $tmpFile,
                                                                 array($watermark, $watermarkMimeType,
                                                                       $watermarkWidth, $watermarkHeight,
-                                                                      'bottom-left', 0, 0));
+                                                                      $watermarkAlignment, 0, 0));
             
             /* Check the return code of the composite operation */
             if ($ret) {
index 56410db22a2428e6d9036729ff764cc377b8db73..d25226a75cd2a4229fa1e28d32f572e4a0360e2a 100644 (file)
     <tr class="gbOdd"><td>watermarkVideos</td><td>true/false</td>
       <td>{g->text text="specify whether you want to apply a watermark to the video thumbnails when they are added."}</td></tr>
 
-    <tr class="gbEven"><td>watermarkImage</td><td>URL path</td>
-      <td>{g->text text="URL path to an alternate image to use as a watermark for all video thumbnails."}</td></tr>
+    <tr class="gbEven"><td>watermarkImage</td><td>URL or local path</td>
+      <td>{g->text text="URL or local path to an alternate image to use as a watermark for all video thumbnails."}</td></tr>
+
+    <tr class="gbEven"><td>watermarkAlignment</td><td>alignment</td>
+      <td>{g->text text="Specify the watermark alignment: top-left, top, top-right, left, center, right, bottom-left, bottom, bottom-right"}</td></tr>
 
 
   </table>