[pLog-svn] r6263 - in plog/trunk/class: action/admin gallery/dao gallery/resizers

mark at devel.lifetype.net mark at devel.lifetype.net
Sun Mar 23 10:43:35 EDT 2008


Author: mark
Date: 2008-03-23 10:43:35 -0400 (Sun, 23 Mar 2008)
New Revision: 6263

Modified:
   plog/trunk/class/action/admin/adminregeneratepreviewaction.class.php
   plog/trunk/class/gallery/dao/galleryresource.class.php
   plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php
Log:
Merge from LifeType 1.2 branch 6247:6258

Modified: plog/trunk/class/action/admin/adminregeneratepreviewaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminregeneratepreviewaction.class.php	2008-03-23 14:17:36 UTC (rev 6262)
+++ plog/trunk/class/action/admin/adminregeneratepreviewaction.class.php	2008-03-23 14:43:35 UTC (rev 6263)
@@ -25,7 +25,16 @@
         $view->setErrorMessage( $this->_locale->tr("error_loading_resource"));
         $this->setValidationErrorView( $view );
     }
-        
+
+    function setCommonData($resource=null){
+        if($resource){
+            $this->_view->setValue( "resourceDescription", $resource->getDescription());
+            $this->_view->setValue( "albumId", $resource->getAlbumId());
+            $this->_view->setValue( "resource", $resource );
+        }
+        parent::setCommonData();
+    }
+    
 	function perform(){
             // first of all, fetch the resource
         $this->_resourceId = $this->_request->getValue( "resourceId" );
@@ -37,74 +46,94 @@
             $this->_view = new AdminResourcesListView( $this->_blogInfo );
             $this->_view->setErrorMessage( $this->_locale->tr("error_loading_resource"));
             $this->setCommonData();
-                
             return false;
         }
             
             // if so, continue... first by checking if the resource is an image or not
             // because if not, then there is no point in generating a thumbnail of it!
         if( !$resource->isImage()) {
-            $this->_view = new AdminResourcesListView( $this->_blogInfo );
+            $this->_view = new AdminEditResourceView( $this->_blogInfo );
             $this->_view->setErrorMessage( $this->_locale->tr("error_resource_is_not_an_image" ));
+            $this->setCommonData($resource);
+            return false;
         }
-            
-            
-        $previewHeight = $this->_config->getValue( "thumbnail_height" );
-        $previewWidth  = $this->_config->getValue( "thumbnail_width" );
-        $previewKeepAspectRatio = $this->_config->getValue( "thumbnails_keep_aspect_ratio" );
 
-            // build the filename
-        $fileNameParts = explode( ".", $resource->getFileName());
-        $fileExt = strtolower($fileNameParts[count($fileNameParts)-1]);
-        $fileName = $resource->getOwnerId()."-".$resource->getId().".".$fileExt;
+            // Get a helper to read the metadata
+        $reader = $resource->getMetadataReader();
+        if(!$reader){
+            $this->_view = new AdminEditResourceView( $this->_blogInfo );
+            $this->_view->setErrorMessage( $this->_locale->tr("error_updating_resource" ));
+            $this->setCommonData($resource);
+            return false;
+        }
 
-            // and start the resizing process
-        $resourceStorage = new GalleryResourceStorage();
-        $resizer = new GalleryResizer( $resourceStorage->getResourcePath( $resource ));
-        $resourceStorage->checkPreviewsStorageFolder( $resource->getOwnerId());
-        $outFile = $resourceStorage->getPreviewsFolder( $resource->getOwnerId()).$fileName;
-            
-            // and finally, we can generate the preview!
-        $result = $resizer->generate( $outFile, $previewHeight, $previewWidth, $previewKeepAspectRatio );
-            
-        $previewFormat = $resizer->getThumbnailFormat();
-        $resource->setThumbnailFormat( $previewFormat );
-        $resources->updateResource( $resource );
-            
+            // We know this is an image, and so can use the imagemetadatareader calls
+        $imgHeight = $reader->getHeight();
+        $imgWidth = $reader->getWidth();
+        
+        lt_include( PLOG_CLASS_PATH."class/gallery/resizers/gallerythumbnailgenerator.class.php" );
+        lt_include( PLOG_CLASS_PATH."class/gallery/dao/galleryresourcestorage.class.php" );
+        lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
+        $config =& Config::getConfig();
+
+        $storage = new GalleryResourceStorage();
+        
+            // delete the small thumbnail
+        $previewFile = GalleryResourceStorage::getPreviewsFolder($resource->getOwnerId()) .
+            $resource->getPreviewFileName();
+        if( File::isReadable($previewFile))
+            File::delete($previewFile);
+
+            // create the new small thumbnail
+        $previewHeight = $config->getValue( "thumbnail_height",
+                                            GALLERY_DEFAULT_THUMBNAIL_HEIGHT );
+        $previewWidth  = $config->getValue( "thumbnail_width",
+                                            GALLERY_DEFAULT_THUMBNAIL_WIDTH );
+        $thumbHeight = ( $imgHeight > $previewHeight ? $previewHeight : $imgHeight );
+        $thumbWidth = ( $imgWidth > $previewWidth ? $previewWidth : $imgWidth );
+
+        $result = GalleryThumbnailGenerator::generateResourceThumbnail(
+            $storage->getResourcePath($resource),
+            $resource->getId(), $resource->getOwnerId(), $thumbHeight, $thumbWidth );
         if( !$result ) {
-            $this->_view = new AdminResourcesListView( $this->_blogInfo );
-            $this->_view->setErrorMessage( $this->_locale->tr("error_generating_resource_preview" ));
+            $this->_view = new AdminEditResourceView( $this->_blogInfo );
+            $this->_view->setErrorMessage( $this->_locale->tr("error_updating_resource" ));
+            $this->setCommonData($resource);
+            return false;
         }
-        else {
-            $previewHeight = $this->_config->getValue( "medium_size_thumbnail_height" );
-            $previewWidth  = $this->_config->getValue( "medium_size_thumbnail_width" );
-            
-            // and start the resizing process
-            $resourceStorage = new GalleryResourceStorage();
-            $resizer = new GalleryResizer( $resourceStorage->getResourcePath( $resource ));
-            $resourceStorage->checkMediumSizePreviewsStorageFolder( $resource->getOwnerId());
-            $outFile = $resourceStorage->getMediumSizePreviewsFolder( $resource->getOwnerId()).$fileName;
-            
-            // and finally, we can generate the preview!
-            $result = $resizer->generate( $outFile, $previewHeight, $previewWidth, $previewKeepAspectRatio );
-            
-            $previewFormat = $resizer->getThumbnailFormat();
-            $resource->setThumbnailFormat( $previewFormat );
-            $resources->updateResource( $resource );
 
-            if( !$result ) {
-                $this->_view = new AdminResourcesListView( $this->_blogInfo );
-                $this->_view->setErrorMessage( $this->_locale->tr("error_generating_resource_medium" ));
-            }
-            else {
-                $this->_view = new AdminEditResourceView( $this->_blogInfo );
-                $this->_view->setSuccessMessage( $message = $this->_locale->tr("resource_preview_generated_ok" ));
-                $this->_view->setValue( "resourceDescription", $resource->getDescription());
-                $this->_view->setValue( "albumId", $resource->getAlbumId());
-                $this->_view->setValue( "resource", $resource );
-            }
+            // delete the medium thumbnail
+        $previewFile = GalleryResourceStorage::getMediumSizePreviewsFolder(
+            $resource->getOwnerId()) . $resource->getMediumSizePreviewFileName();
+        if( File::isReadable($previewFile))
+            File::delete($previewFile);
+
+            // create the new medium thumbnail
+        $previewHeight = $config->getValue( "medium_size_thumbnail_height",
+                                               GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_HEIGHT );
+        $previewWidth  = $config->getValue( "medium_size_thumbnail_width",
+                                               GALLERY_DEFAULT_MEDIUM_SIZE_THUMBNAIL_WIDTH );
+        $thumbHeight = ( $imgHeight > $previewHeight ? $previewHeight : $imgHeight );
+        $thumbWidth = ( $imgWidth > $previewWidth ? $previewWidth : $imgWidth );
+        $result = GalleryThumbnailGenerator::generateResourceMediumSizeThumbnail(
+            $storage->getResourcePath($resource),
+            $resource->getId(), $resource->getOwnerId(), $thumbHeight, $thumbWidth );
+        
+        if( !$result ) {
+            $this->_view = new AdminEditResourceView( $this->_blogInfo );
+            $this->_view->setErrorMessage( $this->_locale->tr("error_updating_resource" ));
+            $this->setCommonData($resource);
+            return false;
         }
-        $this->setCommonData();
+
+            // set new preview format
+        $resource->setThumbnailFormat(
+            $config->getValue("thumbnail_format", THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE));
+        $resources->updateResource( $resource );
+        
+        $this->_view = new AdminEditResourceView( $this->_blogInfo );
+        $this->_view->setSuccessMessage( $message = $this->_locale->tr("resource_preview_generated_ok" ));
+        $this->setCommonData($resource);
             
         return true;
     }

Modified: plog/trunk/class/gallery/dao/galleryresource.class.php
===================================================================
--- plog/trunk/class/gallery/dao/galleryresource.class.php	2008-03-23 14:17:36 UTC (rev 6262)
+++ plog/trunk/class/gallery/dao/galleryresource.class.php	2008-03-23 14:43:35 UTC (rev 6263)
@@ -294,7 +294,7 @@
 		}
 
 		/**
-		 * Sets the descriptoion of the object
+		 * Sets the description of the object
 		 *
 		 * @param description the new description
 		 */
@@ -348,6 +348,7 @@
 		 */
         function getMetadataReader()
         {
+                
         	switch( $this->getResourceType()) {
             	case GalleryConstants::GALLERY_RESOURCE_IMAGE:
                 	$reader = new GalleryResourceImageMetadataReader( $this );
@@ -401,7 +402,9 @@
 			if( $this->getThumbnailFormat() == GalleryConstants::THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE )
 				$previewFile = $fileName;
 			else {
-				$previewFile = str_replace( ".".strtolower($this->getFileExtension()), ".".strtolower($this->getThumbnailFormat()), $fileName );
+                $previewFile = preg_replace("/\.".$this->getFileExtension()."/i",
+                                            ".".strtolower($this->getThumbnailFormat()),
+                                            $fileName);
 			}
 
 			return $previewFile;
@@ -446,8 +449,11 @@
 			// change the file extension, if the thumbnail output format is different from the original file
 			if( $this->getThumbnailFormat() == GalleryConstants::THUMBNAIL_OUTPUT_FORMAT_SAME_AS_IMAGE )
 				$previewFile = $fileName;
-			else
-				$previewFile = str_replace( ".".strtolower($this->getFileExtension()), ".".strtolower($this->getThumbnailFormat()), $fileName );
+			else{
+                $previewFile = preg_replace("/\.".$this->getFileExtension()."/i",
+                                            ".".strtolower($this->getThumbnailFormat()),
+                                            $fileName);
+            }
 
 			return $previewFile;
 		}
@@ -579,4 +585,4 @@
 			return( $data );
 		}
     }
-?>
\ No newline at end of file
+?>

Modified: plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php
===================================================================
--- plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php	2008-03-23 14:17:36 UTC (rev 6262)
+++ plog/trunk/class/gallery/resizers/gallerythumbnailgenerator.class.php	2008-03-23 14:43:35 UTC (rev 6263)
@@ -32,7 +32,7 @@
 			$outFile = GalleryResourceStorage::getPreviewsFolder( $ownerId ).File::basename($resFile);
 			
 			// and finally, we can generate the preview!
-			$result = $resizer->generate( $outFile, $previewHeight, $previewWidth, $previewKeepAspectRatio );
+			$result = $resizer->generate( $outFile, $previewWidth, $previewHeight, $previewKeepAspectRatio );
 			
 			return $result;
 		}



More information about the pLog-svn mailing list