Added debug messages around rescaling the thumbnail
[embedvideo/.git] / ItemAddEmbedVideo.inc
index 28d4a809bee049b1e6a63813bc8aa235a9aed917..460370918a7e19a75e97f642ab05850cc129c3d4 100644 (file)
@@ -18,6 +18,9 @@
  * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
+GalleryCoreApi::requireOnce('modules/gd/classes/GdToolkitHelper.class');
+
+
 /**
  * This plugin will handle the addition of embedded video objects
  * @package embedVideo
@@ -517,8 +520,38 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
               print "<br><br><b>Video Successfully Added to your Gallery Album</b><br><br>";
           }
 
+          /* Resize the thumbnail image to the size indicated by our album */
+          $debugString="";
+          list ($ret, $toolkit) = GalleryCoreApi::getToolkitByOperation($mimeType, 'resize');
+          if (!$ret) {
+              $debugString.="Checking to see if a toolkit that can resize images was found. <br>";
+              if (isset($toolkit)) {
+                  $newTmpFile = $platform->tempnam($tmpDir, 'add');
+                  $newTmpFile.= ".jpg";
+                  $thumbnailSize = 150;
+                  list ($ret, $preferences) =
+                    GalleryCoreApi::fetchDerivativePreferencesForItem($item->getId());
+                  if(!$ret) {
+                      foreach ($preferences as $preference) {
+                        if (preg_match('/thumbnail\|(\d+)/',
+                                       $preference['derivativeOperations'], $matches)) {
+                            $thumbnailSize = $matches[1];
+                            $debugString.="Found thumbnail size in album preferences: $thumbnailSize <br>";
+                            break;
+                        }
+                      }
+                  }
+                  $debugString.="Resizing thumbnail image to $thumbnailSize: $tmpFile -> $newTmpFile <br>";
+                  $toolkit->performOperation($mimeType, 'resize', $tmpFile, $newTmpFile,
+                                             array($thumbnailSize,$thumbnailSize));
+              }
+          }
+          if(!strcmp($debugOutput,"true")) {
+              print "$debugString";
+          }
+          
           /* Make the gallery2 call to add this item to the album */
-          list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($tmpFile,
+          list ($ret, $newItem) = GalleryCoreApi::addItemToAlbum($newTmpFile,
                                                                  $fileName,
                                                                  $title,
                                                                  $summary,
@@ -534,7 +567,13 @@ class ItemAddEmbedVideo extends ItemAddPlugin {
                                           'id' => $newItem->getId(),
                                           'warnings' => array());
        }
-       @$platform->unlink($tmpFile);
+       
+       /* Keep the tmpfiles around if we are in debug mode. Otherwise, remove them. */
+       if(!strcmp($debugOutput,"false")) {
+        @$platform->unlink($tmpFile);
+        @$platform->unlink($newTmpFile);
+       }
+       
    }
    
    return array(null, $error, $status);