[pLog-svn] r2615 - in plog/trunk: class/gallery/dao class/gallery/resizers locale templates/admin

Oscar Renalias oscar at renalias.net
Tue Nov 22 22:17:29 GMT 2005


Yes it can. The only thing this new feature does is replace the  
original image with one of the size specified by  
final_size_thumbnail_height  and final_size_thumbnail_width so  
technically, there is still a file where the original one was. It's  
got the same name, but it's just a smaller version of the original one.

The good thing about this feature is that it allows you to upload big  
files while forcing LT to resize all of them to a certain fixed size  
automatically.

Oscar

On 23 Nov 2005, at 00:13, Jon Daley wrote:

> 	Hrm. we misunderstood each other.
>
> 	Yes, it should only regenerate the preview, that is fine.
>
> 	Can it regenerate the preview if the original image is gone?
>
> On Wed, 23 Nov 2005, Oscar Renalias wrote:
>> But a preview is a preview, right? That feature only regenerates  
>> the previews, it doesn't say that it will regenerate anything else...
>>
>> Oscar
>>
>> On 22 Nov 2005, at 20:39, Jon Daley wrote:
>>
>>> 	I don't know this resource world all that well.  Does your  
>>> change do the right thing if someone hits "regenerate preview" if  
>>> the original image does not exist?
>>> On Tue, 22 Nov 2005, oscar at devel.lifetype.net wrote:
>>>> Author: oscar
>>>> Date: 2005-11-22 17:39:25 +0000 (Tue, 22 Nov 2005)
>>>> New Revision: 2615
>>>> Modified:
>>>>  plog/trunk/class/gallery/dao/galleryresource.class.php
>>>>  plog/trunk/class/gallery/dao/galleryresources.class.php
>>>>  plog/trunk/class/gallery/resizers/ 
>>>> gallerythumbnailgenerator.class.php
>>>>  plog/trunk/locale/locale_en_UK.php
>>>>  plog/trunk/templates/admin/globalsettings_resources.template
>>>> Log:
>>>> Added feature request 336 (http://bugs.lifetype.net/view.php? 
>>>> id=336)
>>>> Modified: plog/trunk/class/gallery/dao/galleryresource.class.php
>>>> ===================================================================
>>>> --- plog/trunk/class/gallery/dao/galleryresource.class.php	 
>>>> 2005-11-22 17:34:19 UTC (rev 2614)
>>>> +++ plog/trunk/class/gallery/dao/galleryresource.class.php	 
>>>> 2005-11-22 17:39:25 UTC (rev 2615)
>>>> @@ -148,6 +148,17 @@
>>>>        {
>>>>        	return $this->_metadata;
>>>>        }
>>>> +
>>>> +		/**
>>>> +		 * Set the resource metadata to the given array
>>>> +		 *
>>>> +		 * @param metadata
>>>> +		 * @return Nothing
>>>> +		 */
>>>> +		function setMetadata( $metadata )
>>>> +		{
>>>> +			$this->_metadata = $metadata;
>>>> +		}
>>>>
>>>> 		/**
>>>> 		 * @return the flags of the resource object
>>>> Modified: plog/trunk/class/gallery/dao/galleryresources.class.php
>>>> ===================================================================
>>>> --- plog/trunk/class/gallery/dao/galleryresources.class.php	 
>>>> 2005-11-22 17:34:19 UTC (rev 2614)
>>>> +++ plog/trunk/class/gallery/dao/galleryresources.class.php	 
>>>> 2005-11-22 17:39:25 UTC (rev 2615)
>>>> @@ -188,17 +188,20 @@
>>>>        								 $ownerId,
>>>>        	                             CACHE_RESOURCES_USER,
>>>>        	                             null,
>>>> - Array( "date" => "ASC" ),
>>>> -        	                             $page,
>>>> -        	                             $itemsPerPage );
>>>> + Array( "date" => "ASC" ));
>>>>            if( !$resources )
>>>> -            	return Array();
>>>> +            	return Array();
>>>>
>>>>           	$result = Array();
>>>>           	foreach( $resources as $resource ) {
>>>> -				if( $this->check( $resource, $ownerId, $albumId,  
>>>> $resourceType ))
>>>> +				if( $this->check( $resource, $ownerId, $albumId,  
>>>> $resourceType )) {
>>>> 					$result[] = $resource;
>>>> +				}
>>>>           	}
>>>> +
>>>> +			// check if we need to do any paging
>>>> +			if( $page > DEFAULT_PAGING_ENABLED && $itemsPerPage >  
>>>> DEFAULT_ITEMS_PER_PAGE )
>>>> +				$result = array_slice( $result, $page, $itemsPerPage );
>>>>
>>>>            return $result;
>>>>        }
>>>> @@ -211,6 +214,7 @@
>>>>                        $albumId = GALLERY_NO_ALBUM,
>>>>                        $resourceType = GALLERY_RESOURCE_ANY )
>>>>        {
>>>> +			//print("check: id = ".$resource->getId()." - owner =  
>>>> $ownerId - album = $albumId - resourceType = $resourceType<br/>");
>>>>        	if( $ownerId != -1 ) {
>>>>        		if( $resource->getOwnerId() != $ownerId )
>>>>        			return false;
>>>> @@ -223,6 +227,7 @@
>>>>           		if( $resource->getResourceType() != $resourceType )
>>>>           			return false;
>>>>           	}
>>>> +
>>>>           	return( true );
>>>>        }
>>>> @@ -237,7 +242,7 @@
>>>> 		 * @see getUserResources
>>>> 		 * @return the total number of items
>>>> 		 */
>>>> -		function getNumUserResources( $ownerId, $albumId =  
>>>> GALLERY_NO_ALBUM, $resourceType = GALLEY_RESOURCE_ANY )
>>>> +		function getNumUserResources( $ownerId, $albumId =  
>>>> GALLERY_NO_ALBUM, $resourceType = GALLERY_RESOURCE_ANY )
>>>> 		{
>>>> 			return( count( $this->getUserResources( $ownerId, $albumId,  
>>>> $resourceType )));
>>>> 		}
>>>> @@ -318,73 +323,9 @@
>>>> 			$this->_cache->removeData( $fileName, CACHE_RESOURCES_BY_NAME );
>>>>
>>>> 			return $resourceId;
>>>> -		}
>>>> -
>>>> -		/**
>>>> -		 * generates the thumbnail of a file that we have just added.
>>>> -		 *
>>>> -		 * @param resFile the resource file from which we're trying  
>>>> to generate the
>>>> -		 * thubmail.
>>>> -		 * @param fileName The name and path of the new thumbnail  
>>>> we're going to create
>>>> -		 */
>>>> -		function generateResourceThumbnail( $resFile, $resourceId,  
>>>> $ownerId )
>>>> -		{
>>>> -			// get some configuration settings regarding the size of the
>>>> -			// thumbnails, and also the default format for thumbnails
>>>> -			$config =& Config::getConfig();
>>>> -			$previewHeight = $config->getValue( "thumbnail_height",  
>>>> GALLERY_DEFAULT_THUMBNAIL_HEIGHT );
>>>> -			$previewWidth  = $config->getValue( "thumbnail_width",  
>>>> GALLERY_DEFAULT_THUMBNAIL_WIDTH );
>>>> -			$previewKeepAspectRatio = $config->getValue 
>>>> ( "thumbnails_keep_aspect_ratio" );
>>>> -
>>>> -			// get the file extension
>>>> -			$fileParts = explode( ".", $resFile );
>>>> -			$fileExt = strtolower($fileParts[count($fileParts)-1]);
>>>> -			$fileName = $ownerId."-".$resourceId.".".$fileExt;
>>>> -
>>>> -			// and start the resizing process
>>>> -			$resizer = new GalleryResizer( $resFile );
>>>> -			GalleryResourceStorage::checkPreviewsStorageFolder( $ownerId );
>>>> -			$outFile = GalleryResourceStorage::getPreviewsFolder 
>>>> ( $ownerId ).$fileName;
>>>> -
>>>> -			// and finally, we can generate the preview!
>>>> -			$result = $resizer->generate( $outFile, $previewWidth,  
>>>> $previewHeight, $previewKeepAspectRatio );
>>>> -
>>>> -			return $result;
>>>> -		}
>>>> +		}
>>>>
>>>> 		/**
>>>> -		 * generates the medium-sized thumbnail of a file that we  
>>>> have just added
>>>> -		 *
>>>> -		 * @param resFile the resource file from which we're trying  
>>>> to generate the
>>>> -		 * thubmail.
>>>> -		 * @param fileName The name and path of the new thumbnail  
>>>> we're going to create
>>>> -		 */
>>>> -		function generateResourceMediumSizeThumbnail( $resFile,  
>>>> $resourceId, $ownerId )
>>>> -		{
>>>> -			// get some configuration settings regarding the size of the
>>>> -			// thumbnails, and also the default format for thumbnails
>>>> -			$config =& Config::getConfig();
>>>> -			$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 );
>>>> -			$previewKeepAspectRatio = $config->getValue 
>>>> ( "thumbnails_keep_aspect_ratio" );
>>>> -
>>>> -			// get the file extension
>>>> -			$fileParts = explode( ".", $resFile );
>>>> -			$fileExt = strtolower($fileParts[count($fileParts)-1]);
>>>> -			$fileName = $ownerId."-".$resourceId.".".$fileExt;
>>>> -
>>>> -			// and start the resizing process
>>>> -			$resizer = new GalleryResizer( $resFile );
>>>> - GalleryResourceStorage::checkMediumSizePreviewsStorageFolder 
>>>> ( $ownerId );
>>>> -			$outFile =  
>>>> GalleryResourceStorage::getMediumSizePreviewsFolder( $ownerId ). 
>>>> $fileName;
>>>> -
>>>> -			// and finally, we can generate the preview!
>>>> -			$result = $resizer->generate( $outFile, $previewWidth,  
>>>> $previewHeight, $previewKeepAspectRatio );
>>>> -
>>>> -			return $result;
>>>> -		}
>>>> -
>>>> -		/**
>>>> 		 * @private
>>>> 		 * @param fileName
>>>> 		 * @param metadata
>>>> @@ -499,6 +440,24 @@
>>>>            	include_once( PLOG_CLASS_PATH."class/gallery/ 
>>>> resizers/gallerythumbnailgenerator.class.php" );
>>>>                 
>>>> GalleryThumbnailGenerator::generateResourceThumbnail( $resFile,  
>>>> $resourceId, $ownerId );
>>>> 				 
>>>> GalleryThumbnailGenerator::generateResourceMediumSizeThumbnail 
>>>> ( $resFile, $resourceId, $ownerId );
>>>> +				// call this method only if the settings are right
>>>> +				include_once( PLOG_CLASS_PATH."class/config/ 
>>>> config.class.php" );
>>>> +				$config =& Config::getConfig();
>>>> +				$previewHeight = $config->getValue 
>>>> ( "final_size_thumbnail_height", 0 );
>>>> +				$previewWidth  = $config->getValue 
>>>> ( "final_size_thumbnail_width", 0 );
>>>> +				if( $previewHeight != 0 && $previewWidth != 0 ) {
>>>> + GalleryThumbnailGenerator::generateResourceFinalSizeThumbnail 
>>>> ( $resFile, $resourceId, $ownerId );
>>>> +					// we have to recalculate the metadata because the image  
>>>> could be different... This is a bit cumbersome
>>>> +					// and repeats code. We know, thanks.
>>>> +					$getId3 = new GetID3();
>>>> +					$metadata = $getId3->analyze( $resFile );
>>>> + getid3_lib::CopyTagsToComments($metadata);
>>>> +					$info = $this->_filterMetadata( $metadata, $resourceType );
>>>> +					// and finally update the resource again
>>>> +					$resource = $this->getResource( $resourceId );
>>>> +					$resource->setMetadata( $info );
>>>> +					$this->updateResource( $resource );
>>>> +				}
>>>>            }
>>>>
>>>>            // return the id of the resource we just added
>>>> @@ -608,7 +567,9 @@
>>>>            // move the file to disk
>>>> 		    include_once( PLOG_CLASS_PATH."class/gallery/dao/ 
>>>> galleryresourcestorage.class.php" );
>>>>            $storage = new GalleryResourceStorage();
>>>> -            $resFile = $storage->storeFile( $resourceId,  
>>>> $ownerId, $fullFilePath,
>>>> +            $resFile = $storage->storeFile( $resourceId,
>>>> +			                                $ownerId,
>>>> + $fullFilePath,
>>>>                                             
>>>> RESOURCE_STORAGE_STORE_MOVE );
>>>>
>>>>            // if the file cannot be read, we will also remove  
>>>> the record from the
>>>> @@ -626,9 +587,28 @@
>>>>
>>>>            // and finally, we can generate the thumbnail only if  
>>>> the file is an image, of course :)
>>>>            if( $resourceType == GALLERY_RESOURCE_IMAGE ) {
>>>> -            	include_once( PLOG_CLASS_PATH."class/gallery/ 
>>>> resizers/gallerythumbnailgenerator.class.php" );
>>>> +            	include_once( PLOG_CLASS_PATH."class/gallery/ 
>>>> resizers/gallerythumbnailgenerator.class.php" );
>>>>                 
>>>> GalleryThumbnailGenerator::generateResourceThumbnail( $resFile,  
>>>> $resourceId, $ownerId );
>>>> -            }
>>>> + GalleryThumbnailGenerator::generateResourceMediumSizeThumbnail 
>>>> ( $resFile, $resourceId, $ownerId );
>>>> +				// call this method only if the settings are right
>>>> +				include_once( PLOG_CLASS_PATH."class/config/ 
>>>> config.class.php" );
>>>> +				$config =& Config::getConfig();
>>>> +				$previewHeight = $config->getValue 
>>>> ( "final_size_thumbnail_height", 0 );
>>>> +				$previewWidth  = $config->getValue 
>>>> ( "final_size_thumbnail_width", 0 );
>>>> +				if( $previewHeight != 0 && $previewWidth != 0 ) {
>>>> + GalleryThumbnailGenerator::generateResourceFinalSizeThumbnail 
>>>> ( $resFile, $resourceId, $ownerId );
>>>> +					// we have to recalculate the metadata because the image  
>>>> could be different... This is a bit cumbersome
>>>> +					// and repeats code. We know, thanks.
>>>> +					$getId3 = new GetID3();
>>>> +					$metadata = $getId3->analyze( $resFile );
>>>> + getid3_lib::CopyTagsToComments($metadata);
>>>> +					$info = $this->_filterMetadata( $metadata, $resourceType );
>>>> +					// and finally update the resource again
>>>> +					$resource = $this->getResource( $resourceId );
>>>> +					$resource->setMetadata( $info );
>>>> +					$this->updateResource( $resource );
>>>> +				}
>>>> +			}
>>>>
>>>>            // return the id of the resource we just added
>>>>            return $resourceId;
>>>> Modified: plog/trunk/class/gallery/resizers/ 
>>>> gallerythumbnailgenerator.class.php
>>>> ===================================================================
>>>> --- plog/trunk/class/gallery/resizers/ 
>>>> gallerythumbnailgenerator.class.php 2005-11-22 17:34:19 UTC (rev  
>>>> 2614)
>>>> +++ plog/trunk/class/gallery/resizers/ 
>>>> gallerythumbnailgenerator.class.php 2005-11-22 17:39:25 UTC (rev  
>>>> 2615)
>>>> @@ -1,7 +1,5 @@
>>>> -<?php
>>>> -
>>>> +<?php
>>>> -
>>>> 	class GalleryThumbnailGenerator
>>>> 	{
>>>> @@ -75,6 +73,44 @@
>>>> 			$result = $resizer->generate( $outFile, $previewWidth,  
>>>> $previewHeight, $previewKeepAspectRatio );
>>>>
>>>> 			return $result;
>>>> -		}
>>>> +		}
>>>> +
>>>> +		/**
>>>> +		 * generates the final version of an image
>>>> +		 *
>>>> +		 * @param resFile the resource file from which we're trying  
>>>> to generate the
>>>> +		 * thubmail.
>>>> +		 * @param fileName The name and path of the new thumbnail  
>>>> we're going to create
>>>> +		 * @static
>>>> +		 */
>>>> +		function generateResourceFinalSizeThumbnail( $resFile,  
>>>> $resourceId, $ownerId )
>>>> +		{
>>>> +			// get some configuration settings regarding the size of the
>>>> +			// thumbnails, and also the default format for thumbnails
>>>> +			include_once( PLOG_CLASS_PATH."class/config/ 
>>>> config.class.php" );
>>>> +			$config =& Config::getConfig();
>>>> +			$previewHeight = $config->getValue 
>>>> ( "final_size_thumbnail_height", 0 );
>>>> +			$previewWidth  = $config->getValue 
>>>> ( "final_size_thumbnail_width", 0 );
>>>> +			$previewKeepAspectRatio = $config->getValue 
>>>> ( "thumbnails_keep_aspect_ratio" );
>>>> +
>>>> +			// get the file extension
>>>> +			$fileParts = explode( ".", $resFile );
>>>> +			$fileExt = strtolower($fileParts[count($fileParts)-1]);
>>>> +			$fileName = $ownerId."-".$resourceId.".".$fileExt;
>>>> +
>>>> +			print("final size = $previewHeight x $previewWidth - file =  
>>>> $fileName<br/>");
>>>> +
>>>> +			// and start the resizing process
>>>> +		    include_once( PLOG_CLASS_PATH."class/gallery/resizers/ 
>>>> galleryresizer.class.php" );
>>>> +			$resizer = new GalleryResizer( $resFile );
>>>> +		    include_once( PLOG_CLASS_PATH."class/gallery/dao/ 
>>>> galleryresourcestorage.class.php" );
>>>> +			GalleryResourceStorage::checkUserStorageFolder( $ownerId );
>>>> +			$outFile = GalleryResourceStorage::getUserFolder( $ownerId ). 
>>>> $fileName;
>>>> +
>>>> +			// and finally, we can generate the preview!
>>>> +			$result = $resizer->generate( $outFile, $previewWidth,  
>>>> $previewHeight, $previewKeepAspectRatio );
>>>> +
>>>> +			return $result;
>>>> +		}
>>>> 	}
>>>> ?>
>>>> \ No newline at end of file
>>>> Modified: plog/trunk/locale/locale_en_UK.php
>>>> ===================================================================
>>>> --- plog/trunk/locale/locale_en_UK.php	2005-11-22 17:34:19 UTC  
>>>> (rev 2614)
>>>> +++ plog/trunk/locale/locale_en_UK.php	2005-11-22 17:39:25 UTC  
>>>> (rev 2615)
>>>> @@ -956,6 +956,8 @@
>>>> $messages['help_page_suffix_format'] = 'Suffix that will be  
>>>> appended to URLs that support paging';
>>>> +$messages['help_final_size_thumbnail_width'] = 'Final width of  
>>>> uploaded images. Leave empty or as zero to store the full size  
>>>> image';
>>>> +$messages['help_final_size_thumbnail_height'] = 'Final height  
>>>> of uploaded images. Leave empty or as zero to store the full  
>>>> size image';
>>>> $messages['error_comment_too_big'] = 'The comment is too big';
>>>> $messages['error_you_have_been_blocked'] = 'Blocked: this  
>>>> request was not completed.';
>>>> $messages['created'] = 'Created';
>>>> Modified: plog/trunk/templates/admin/ 
>>>> globalsettings_resources.template
>>>> ===================================================================
>>>> --- plog/trunk/templates/admin/globalsettings_resources.template  
>>>> 2005-11-22 17:34:19 UTC (rev 2614)
>>>> +++ plog/trunk/templates/admin/globalsettings_resources.template  
>>>> 2005-11-22 17:39:25 UTC (rev 2615)
>>>> @@ -51,18 +51,30 @@
>>>>    <div class="formHelp">{$locale->tr("help_thumbnail_width")}</ 
>>>> div>
>>>>    <input style="width:100%" type="text" name="config 
>>>> [thumbnail_width]" value="{$thumbnail_width}"/>
>>>>   </div>
>>>> +   <!-- medium_size_thumbnail_width -->
>>>> +   <div class="field">
>>>> +    <label for="config 
>>>> [medium_size_thumbnail_width]">medium_size_thumbnail_width</label>
>>>> +    <div class="formHelp">{$locale->tr 
>>>> ("help_medium_size_thumbnail_width")}</div>
>>>> +    <input style="width:100%" type="text" name="config 
>>>> [medium_size_thumbnail_width]"  
>>>> value="{$medium_size_thumbnail_width}"/>
>>>> +   </div>
>>>>   <!-- medium_size_thumbnail_height -->
>>>>   <div class="field">
>>>>    <label for="config 
>>>> [medium_size_thumbnail_height]">medium_size_thumbnail_height</ 
>>>> label>
>>>>    <div class="formHelp">{$locale->tr 
>>>> ("help_medium_size_thumbnail_height")}</div>
>>>>    <input style="width:100%" type="text" name="config 
>>>> [medium_size_thumbnail_height]"  
>>>> value="{$medium_size_thumbnail_height}"/>
>>>> -   </div>
>>>> -   <!-- medium_size_thumbnail_width -->
>>>> +   </div>
>>>> +   <!-- final_size_thumbnail_width -->
>>>>   <div class="field">
>>>> -    <label for="config 
>>>> [medium_size_thumbnail_width]">medium_size_thumbnail_width</label>
>>>> -    <div class="formHelp">{$locale->tr 
>>>> ("help_medium_size_thumbnail_width")}</div>
>>>> -    <input style="width:100%" type="text" name="config 
>>>> [medium_size_thumbnail_width]"  
>>>> value="{$medium_size_thumbnail_width}"/>
>>>> +    <label for="config 
>>>> [final_size_thumbnail_width]">final_size_thumbnail_width</label>
>>>> +    <div class="formHelp">{$locale->tr 
>>>> ("help_final_size_thumbnail_width")}</div>
>>>> +    <input style="width:100%" type="text" name="config 
>>>> [final_size_thumbnail_width]"  
>>>> value="{$final_size_thumbnail_width}"/>
>>>>   </div>
>>>> +   <!-- final_size_thumbnail_height -->
>>>> +   <div class="field">
>>>> +    <label for="config 
>>>> [final_size_thumbnail_height]">final_size_thumbnail_height</label>
>>>> +    <div class="formHelp">{$locale->tr 
>>>> ("help_final_size_thumbnail_height")}</div>
>>>> +    <input style="width:100%" type="text" name="config 
>>>> [final_size_thumbnail_height]"  
>>>> value="{$final_size_thumbnail_height}"/>
>>>> +   </div>
>>>>   <!-- thumbnails_keep_aspect_ratio -->
>>>>   <div class="field">
>>>>    <label for="config 
>>>> [thumbnails_keep_aspect_ratio]">thumbnails_keep_aspect_ratio</ 
>>>> label>
>>>> _______________________________________________
>>>> pLog-svn mailing list
>>>> pLog-svn at devel.lifetype.net
>>>> http://devel.plogworld.net/mailman/listinfo/plog-svn
>>> **************************************
>>> Jon Daley
>>> http://jon.limedaley.com/
>>> Never mess up an apology with an excuse.
>>> _______________________________________________
>>> pLog-svn mailing list
>>> pLog-svn at devel.lifetype.net
>>> http://devel.plogworld.net/mailman/listinfo/plog-svn
>>
>> _______________________________________________
>> pLog-svn mailing list
>> pLog-svn at devel.lifetype.net
>> http://devel.plogworld.net/mailman/listinfo/plog-svn
>
> **************************************
> Jon Daley
> http://jon.limedaley.com/
>
> If you obey all the rules, you miss all the fun.
> -- Katharine Hepburn
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.lifetype.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>




More information about the pLog-svn mailing list