<?php	
	
	class GalleryThumbnailGenerator 
	{
	
		/**
		 * 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
		 * @static
		 */
		function generateResourceThumbnail( $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( "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
			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::checkPreviewsStorageFolder( $ownerId );
			$outFile = GalleryResourceStorage::getPreviewsFolder( $ownerId ).$fileName;
			
			// and finally, we can generate the preview!
			$result = $resizer->generate( $outFile, $previewHeight, $previewWidth, $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
		 * @static
		 */
		function generateResourceMediumSizeThumbnail( $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( "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
		    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::checkMediumSizePreviewsStorageFolder( $ownerId );
			$outFile = GalleryResourceStorage::getMediumSizePreviewsFolder( $ownerId ).$fileName;
			
			// and finally, we can generate the preview!
			$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 = $fileParts[count($fileParts)-1];
			$fileName = $ownerId."-".$resourceId.".".$fileExt;
			
			// 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;
		}				
	}
?>