Source for file ImageManager.php
Documentation is available at ImageManager.php
* ImageManager, list images, directories, and thumbnails.
require_once('Files.php');
* Array of directory information.
* Constructor. Create a new Image Manager instance.
* @param array $config configuration array, see config.inc.php
* Get the base directory.
* @return string base dir, see config.inc.php
Return $this->config['base_dir'];
* @return string base url, see config.inc.php
Return $this->config['base_url'];
* Get the tmp file prefix.
* @return string tmp file prefix.
Return $this->config['tmp_prefix'];
* Get the sub directories in the base dir.
* Each array element contain
* the relative path (relative to the base dir) as key and the
* @return array of sub directries
* <code>array('path name' => 'full directory path', ...)</code>
* Recursively travese the directories to get a list
* of accessable directories.
* @param string $base the full path to the current directory
* @param string $path the relative path name
* @return array of accessiable sub-directories
* <code>array('path name' => 'full directory path', ...)</code>
function _dirs($base, $path)
while (false !==
($entry =
$d->read()))
//If it is a directory, and it doesn't start with
// a dot, and if is it not the thumbnail directory
$dirs[$relative] =
$fullpath;
* Get all the files and directories of a relative path.
* @param string $path relative path to be base path.
* @return array of file and path information.
* <code>array(0=>array('relative'=>'fullpath',...), 1=>array('filename'=>fileinfo array(),...)</code>
* fileinfo array: <code>array('url'=>'full url',
* 'relative'=>'relative to base',
* 'fullpath'=>'full file path',
* 'image'=>imageInfo array() false if not image,
* 'stat' => filestat)</code>
return array($files,$dirs);
while (false !==
($entry =
$d->read()))
//not a dot file or directory
$dirs[$relative] =
array('fullpath'=>
$full,'entry'=>
$entry,'count'=>
$count);
$file['relative'] =
$path.
$entry;
$file['fullpath'] =
$fullpath.
$entry;
$file['stat'] =
stat($fullpath.
$entry);
Return array($dirs, $files);
* Count the number of files and directories in a given folder
* minus the thumbnail folders and thumbnails.
while (false !==
($entry =
$d->read()))
&&
$this->isThumb($entry) ==
false)
* Get image size information.
* @param string $file the image file
* @return array of getImageSize information,
* false if the file is not an image.
Return @getImageSize($file);
* Check if the file contains the thumbnail prefix.
* @param string $file filename to be checked
* @return true if the file contains the thumbnail prefix, false otherwise.
* Check if the given directory is a thumbnail directory.
* @param string $entry directory name
* @return true if it is a thumbnail directory, false otherwise
if($this->config['thumbnail_dir'] ==
false
Return ($entry ==
$this->config['thumbnail_dir']);
* Check if the given file is a tmp file.
* @param string $file file name
* @return boolean true if it is a tmp file, false otherwise
* For a given image file, get the respective thumbnail filename
* no file existence check is done.
* @param string $fullpathfile the full path to the image file
* @return string of the thumbnail file
$thumbnail =
$this->config['thumbnail_prefix'].
$path_parts['basename'];
if($this->config['safe_mode'] ==
true
else //should this ever happen?
//error_log('ImageManager: Error in creating thumbnail name');
* Similar to getThumbName, but returns the URL, base on the
* given base_url in config.inc.php
* @param string $relative the relative image file name,
* relative to the base_dir path
* @return string the url of the thumbnail
$thumbnail =
$this->config['thumbnail_prefix'].
$path_parts['basename'];
if($path_parts['dirname']==
'\\') $path_parts['dirname']=
'/';
if($this->config['safe_mode'] ==
true
else //should this ever happen?
//error_log('ImageManager: Error in creating thumbnail url');
* Check if the given path is part of the subdirectories
* @param string $path the relative path to be checked
* @return boolean true if the path exists, false otherwise
//check the path given in the url against the
//list of paths in the system.
for($i =
0; $i <
count($dirs); $i++
)
* Process uploaded files, assumes the file is in
* $_FILES['upload'] and $_POST['dir'] is set.
* The dir must be relative to the base_dir and exists.
* If 'validate_images' is set to true, only file with
* image dimensions will be accepted.
//check for the file, and must have valid relative path
* Process upload files. The file must be an
* uploaded file. If 'validate_images' is set to
* true, only images will be processed. Any duplicate
* file will be renamed. See Files::copyFile for details
* @param string $relative the relative path where the file
* @param array $file the uploaded file from $_FILES
* @return boolean true if the file was processed successfully,
if($this->config['validate_images'] ==
true)
$imgInfo =
@getImageSize($file['tmp_name']);
$result =
Files::copyFile($file['tmp_name'], $path, $file['name']);
* Get the URL of the relative file.
* basically appends the relative file to the
* base_url given in config.inc.php
* @param string $relative a file the relative to the base_dir
* @return string the URL of the relative file.
* Get the fullpath to a relative file.
* @param string $relative the relative file.
* @return string the full path, .ie. the base_dir + relative.
* Get the default thumbnail.
* @return string default thumbnail, empty string if
* the thumbnail doesn't exist.
Return $this->config['default_thumbnail'];
* Get the thumbnail url to be displayed.
* If the thumbnail exists, and it is up-to-date
* the thumbnail url will be returns. If the
* file is not an image, a default image will be returned.
* If it is an image file, and no thumbnail exists or
* the thumbnail is out-of-date (i.e. the thumbnail
* modified time is less than the original file)
* then a thumbs.php?img=filename.jpg is returned.
* The thumbs.php url will generate a new thumbnail
* on the fly. If the image is less than the dimensions
* of the thumbnails, the image will be display instead.
* @param string $relative the relative image file.
* @return string the url of the thumbnail, be it
* actually thumbnail or a script to generate the
$imgInfo =
@getImageSize($fullpath);
//the original image is smaller than thumbnails,
//so just return the url to the original image.
if ($imgInfo[0] <=
$this->config['thumbnail_width']
&&
$imgInfo[1] <=
$this->config['thumbnail_height'])
//check for thumbnails, if exists and
// it is up-to-date, return the thumbnail url
//well, no thumbnail was found, so ask the thumbs.php
//to generate the thumbnail on the fly.
* Delete and specified files.
* @return boolean true if delete, false otherwise
* Delete and specified directories.
* @return boolean true if delete, false otherwise
* Delete the relative file, and any thumbnails.
* @param string $relative the relative file.
* @return boolean true if deleted, false otherwise.
//check that the file is an image
if($this->config['validate_images'] ==
true)
return false; //hmmm not an Image!!???
* Delete directories recursively.
* @param string $relative the relative path to be deleted.
* @return boolean true if deleted, false otherwise.
* Create new directories.
* If in safe_mode, nothing happens.
* @return boolean true if created, false otherwise.
if($this->config['safe_mode'] ==
true)
if(isset
($_GET['newDir']) && isset
($_GET['dir']))
* Do some graphic library method checkings
* @param string $library the graphics library, GD, NetPBM, or IM.
* @param string $method the method to check.
* @return boolean true if able, false otherwise.
return $this->_checkNetPBMLibrary($method);
//ImageMagick goes throught 1 single executable
* Check the GD library functionality.
* @param string $library the graphics library, GD, NetPBM, or IM.
* @return boolean true if able, false otherwise.
Documentation generated on Mon, 05 May 2008 16:20:24 +0400 by phpDocumentor 1.4.0