Initial stab at getting the thumbnail resize feature working.
authorAlan Jack Pippin <ajp@pippin.(none)>
Sun, 1 Jul 2007 06:35:06 +0000 (00:35 -0600)
committerAlan J. Pippin <ajp@pippins.net>
Sun, 1 Jul 2007 06:35:06 +0000 (00:35 -0600)
ItemAddEmbedVideo.inc
module.inc

index 28d4a809bee049b1e6a63813bc8aa235a9aed917..6d1e8d7c5f26f945d6d670856bbf2c38ce1b762e 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,36 @@ 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 */
+          list ($ret, $toolkit) = GalleryCoreApi::getToolkitByOperation($mimeType, 'resize');
+          if (!$ret) {
+            if(!strcmp($debugOutput,"true")) {
+              print "Checking to see if toolkit 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];
+                    break;
+                  }
+                }
+              }
+              if(!strcmp($debugOutput,"true")) {
+                print "Resizing thumbnail image to $thumbnailSize: $tmpFile -> $newTmpFile <br>";
+              }
+              $toolkit->performOperation($mimeType, 'resize', $tmpFile, $newTmpFile,
+                                         array($thumbnailSize,$thumbnailSize));
+            }
+          }
+          
           /* 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 +565,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);
index eb03f50eec423bca540cc9288ecc2e0a59a5ca03..9ca5ffb972139c867ad32cf1135ba9555d27fcd5 100644 (file)
@@ -33,7 +33,7 @@ class EmbedVideoModule extends GalleryModule {
        $this->setId('embedvideo');
        $this->setName($gallery->i18n('Embed Video'));
        $this->setDescription($gallery->i18n('Add embedded videos from the web'));
-       $this->setVersion('1.0.1');
+       $this->setVersion('1.0.2');
        $this->setGroup('import', $gallery->i18n('Import'));
        $this->setCallbacks('getSiteAdminViews');
        $this->setRequiredCoreApi(array(7, 4));