Source for file ImageEditor.php
Documentation is available at ImageEditor.php
* Image Editor. Editing tools, crop, rotate, scale and save.
require_once('Transform.php');
* Handles the basic image editing capbabilities.
* user based on IP address
* Create a new ImageEditor instance. Editing requires a
* tmp file, which is saved in the current directory where the
* image is edited. The tmp file is assigned by md5 hash of the
* user IP address. This hashed is used as an ID for cleaning up
* the tmp files. In addition, any tmp files older than the
* the specified period will be deleted.
* @param ImageManager $manager the image manager, we need this
* for some file and path handling functions.
$this->_uid =
md5($_SERVER['REMOTE_ADDR']);
* @return int 1 if the file was saved sucessfully,
* 0 no save operation, -1 file save error.
* Process the image, if not action, just display the image.
* @return array with image information, empty array if not an image.
* <code>array('src'=>'url of the image', 'dimensions'=>'width="xx" height="yy"',
* 'file'=>'image file, relative', 'fullpath'=>'full path to the image');</code>
//$relative = '/Series2004NoteFront.jpg';
$imgURL =
$this->manager->getFileURL($relative);
$fullpath =
$this->manager->getFullPath($relative);
$imgInfo =
@getImageSize($fullpath);
$image['dimensions'] =
$imgInfo[3];
$image['file'] =
$relative;
$image['fullpath'] =
$fullpath;
* Process the actions, crop, scale(resize), rotate, flip, and save.
* When ever an action is performed, the result is save into a
* temporary image file, see createUnique on the filename specs.
* It does not return the saved file, alway returning the tmp file.
* @param string $action, should be 'crop', 'scale', 'rotate','flip', or 'save'
* @param string $relative the relative image filename
* @param string $fullpath the fullpath to the image file
* @return array with image information
* <code>array('src'=>'url of the image', 'dimensions'=>'width="xx" height="yy"',
* 'file'=>'image file, relative', 'fullpath'=>'full path to the image');</code>
if(isset
($_GET['params']))
$params =
$_GET['params'];
else if($values[0] ==
'ver')
$quality =
intval($values[1]);
if($quality <
0) $quality =
85;
//get unique filename just returns the filename, so
//we need to make the relative path once more.
$newSaveFile =
$this->makeRelative($relative, $newSaveFile);
$newSaveFullpath =
$this->manager->getFullPath($newSaveFile);
$img->save($newSaveFullpath, $values[0], $quality);
//create the tmp image file
$newFullpath =
$this->manager->getFullPath($newRelative);
$newURL =
$this->manager->getFileURL($newRelative);
$img->save($newFullpath);
//get the image information
$image['dimensions'] =
$imgInfo[3];
$image['file'] =
$newRelative;
$image['fullpath'] =
$newFullpath;
* Get the file name base on the save name
* @param string $type image type, 'jpeg', 'png', or 'gif'
* @return string the filename according to save type
if(!isset
($_GET['file']))
$base =
substr($filename,0,$index);
if($type ==
'jpeg' &&
!($ext==
'jpeg' ||
$ext==
'jpg'))
if($type==
'png' &&
$ext !=
'png')
if($type==
'gif' &&
$ext !=
'gif')
* Get the default save file name, used by editor.php.
* @return string a suggestive filename, this should be unique
* Get a unique filename. If the file exists, the filename
* base is appended with an increasing integer.
* @param string $relative the relative filename to the base_dir
* @return string a unique filename in the current path
$fullpath =
$this->manager->getFullPath($relative);
$ext =
substr($file, $dotIndex);
$base =
substr($file, 0, $dotIndex);
$filename =
$base.
'_'.
$counter.
$ext;
* Specifiy the original relative path, a new filename
* and return the new filename with relative path.
* i.e. $pathA (-filename) + $file
* @param string $pathA the relative file
* @param string $file the new filename
* @return string relative path with the new filename
$path =
substr($pathA, 0, $index);
* Get the action GET parameter
* @return string action parameter
if(isset
($_GET['action']))
$action =
$_GET['action'];
* Generate a unique string based on md5(microtime()).
* Well not so uniqe, as it is limited to 6 characters
* @return string unique string.
* Create unique tmp image file name.
* The filename is based on the tmp file prefix
* specified in config.inc.php plus
* the UID (basically a md5 of the remote IP)
* and some random 6 character string.
* This function also calls to clean up the tmp files.
* @param string $file the fullpath to a file
* @return string a unique filename for that path
* NOTE: it only returns the filename, path no included.
//make sure the the unique temp file does not exists
$this->cleanUp($path,$pathinfo['basename']);
* Delete any tmp image files.
* @param string $path the full path
* where the clean should take place.
$tmp =
$this->manager->getTmpPrefix();
$prefix =
$tmp.
$this->_uid;
while (false !==
($entry =
$d->read()))
if(substr($entry,0,$len)==
$prefix &&
$entry !=
$file)
else if(substr($entry,0,$tmpLen)==
$tmp &&
$entry !=
$file)
* Get the image type base on an image file.
* @param string $file the full path to the image file.
* @return string of either 'gif', 'jpeg', 'png' or 'bmp'
* otherwise it will return null.
$imageInfo =
@getImageSize($file);
* Check if the specified image can be edit by GD
* mainly to check that GD can read and save GIFs
* @return int 0 if it is not a GIF file, 1 is GIF is editable, -1 if not editable.
$fullpath =
$this->manager->getFullPath($relative);
* Check if GIF can be edit by GD.
* @return int 0 if it is not using the GD library, 1 is GIF is editable, -1 if not editable.
Documentation generated on Mon, 05 May 2008 16:20:19 +0400 by phpDocumentor 1.4.0