Source for file OCSP_IMAGE.phpclass
Documentation is available at OCSP_IMAGE.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
// ---------------------------------------------------------
// ---------------------------------------------------------
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @constant string CLASS_SRC_FILE
* minimal width when resizing
* minimal width when resizing
* @var resource $myImgRes
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// constructor init, and attribut getting / settings
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* sets the image file to $file
* if $file does not exists
* $OCSP_CONF['PROJECTPATH'].$file and
* $_SERVER['DOCUMENT_ROOT'] is also checked
} // end of member function getWidth
} // end of member function getHeight
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* sets the minimum width for resize
* sets the minimum height for resize
* calculates the width and height the image must have to
* fit into the $with and $height
* @param boolean $enlarge
* @version pk-07-11-27 (0 values of $width and $height)
* @version pk-07-11-27 (return value)
public function getFitSize(&$width, &$height, $enlarge=
False,$debug=
False)
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"max: $i_maxWidth x $i_maxHeight orignial: $width x $height<br/>");
while ($width >
$i_maxWidth) {
$width =
floor($width *
0.99);
$height =
floor($height *
0.99);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"max: $i_maxWidth x $i_maxHeight new1: $width x $height<br/>");
while ($height >
$i_maxHeight) {
$width =
floor($width *
0.99);
$height =
floor($height *
0.99);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"max: $i_maxWidth x $i_maxHeight new2: $width x $height<br/>");
while ($width <
$i_maxWidth) {
$width =
floor($width *
1.01);
$height =
floor($height *
1.01);
while ($height <
$i_maxHeight) {
$width =
floor($width *
1.01);
$height =
floor($height *
1.01);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"max: $i_maxWidth x $i_maxHeight new3: $width x $height<br/>");
* resize the image and overwrites the original location
public function resize($width,$height,$debug=
False)
* returns the mimetype of the image
* @param int $aType (if !intval this->type is used)
* @todo implementation for other types then gif,jpeg and png
default:
// create an empty image
* returns the Fileextension of the image type
* @param int $aType (if !intval this->type is used)
* @todo implementation for other types then gif,jpeg and png
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* creates the image from the source (if file exists)
* @todo implementation for other types then gif,jpeg and png
default:
// create an empty image
* resizes the resource to width and height
return True; // nothing to do
* returns the resource for output
* @param int $asType 0=same as image
public function res_get($asType=
0) {
$i_type=
(intval($asType) ?
$asType :
$this->type);
* @param string $fileName (empty will overwrite the image)
* @param int $asType 0=same as image
* @param bool $testType (if true and imagexxx fails the next one is tried)
* @returns int (type number)
public function res_saveAs($fileName=
"",$asType=
0,$testType=
False) {
$i_type=
(intval($asType) ?
$asType :
$this->type);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* echos the image with headers
* @param boolean $useCache
* @param boolean $enlarge
* @return boolean if success
public function output($width=
0,$height=
0,$useCache=
True,$enlarge=
False,$debug=
False)
header("Cache-Control: public");
if ($this->getFitSize($width,$height,$enlarge,$debug))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"cachefile: " .
$str_cacheFile);
if (!self::isFile($str_cacheFile))
$fp=
fopen($str_cacheFile, "rb");
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* @param boolean $autoCreate
protected function getCacheFilePath($width,$height,$autoCreate=
True,$debug=
False)
* generates a cahce file if the image does not fit otherwithe returns false
* NOTE does not free the resource
* @param boolean $enlarge
if (!$this->getFitSize($width,$height,$enlarge,$debug))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"CacheFile: " .
$str_cacheFile);
* removes the cache files
foreach($arr_files as $str_file)
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
Documentation generated on Thu, 08 Jan 2009 17:46:53 +0100 by phpDocumentor 1.4.0a2