[pLog-svn] r6251 - plog/branches/lifetype-1.2/class/action/admin
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Fri Mar 21 14:30:22 EDT 2008
Author: jondaley
Date: 2008-03-21 14:30:22 -0400 (Fri, 21 Mar 2008)
New Revision: 6251
Modified:
plog/branches/lifetype-1.2/class/action/admin/adminregeneratepreviewaction.class.php
Log:
fixes 1473, where regenerate doesn't work for non-encoded filenames. more work to come
Modified: plog/branches/lifetype-1.2/class/action/admin/adminregeneratepreviewaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminregeneratepreviewaction.class.php 2008-03-21 17:26:41 UTC (rev 6250)
+++ plog/branches/lifetype-1.2/class/action/admin/adminregeneratepreviewaction.class.php 2008-03-21 18:30:22 UTC (rev 6251)
@@ -37,7 +37,6 @@
$this->_view = new AdminResourcesListView( $this->_blogInfo );
$this->_view->setErrorMessage( $this->_locale->tr("error_loading_resource"));
$this->setCommonData();
-
return false;
}
@@ -46,64 +45,67 @@
if( !$resource->isImage()) {
$this->_view = new AdminResourcesListView( $this->_blogInfo );
$this->_view->setErrorMessage( $this->_locale->tr("error_resource_is_not_an_image" ));
+ $this->setCommonData();
+ 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 AdminResourcesListView( $this->_blogInfo );
+ $this->_view->setErrorMessage( $this->_locale->tr("error_updating_resource" ));
+ $this->setCommonData();
+ 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, $previewWidth, $previewHeight, $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();
+
+ $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(
+ GalleryResourceStorage::getUserFolder($resource->getOwnerId()).$resource->getFileName(),
+ $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->setErrorMessage( $this->_locale->tr("error_updatin_resource" ));
+ $this->setCommonData();
+ 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, $previewWidth, $previewHeight, $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 );
- }
+
+ $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(
+ GalleryResourceStorage::getUserFolder($resource->getOwnerId()).$resource->getFileName(),
+ $resource->getId(), $resource->getOwnerId(), $thumbHeight, $thumbWidth );
+
+ if( !$result ) {
+ $this->_view = new AdminResourcesListView( $this->_blogInfo );
+ $this->_view->setErrorMessage( $this->_locale->tr("error_updating_resource" ));
}
+ 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 );
+ }
$this->setCommonData();
return true;
More information about the pLog-svn
mailing list