image_ratio Class Reference

List of all members.

Static Public Member Functions

  • static getInstance ()
  • static resetInstance ()
  • static tep_image ($src, $alt= '', $width= '', $height= '', $parameters= '', $mode=false)
    The HTML image wrapper function.
  • static get_image ($src, $alt= '', $width= '', $height= '')
    Recup des info d'une image.

Static Protected Attributes

Private Member Functions

Static Private Member Functions

  • static initCurrent ($src, $width, $height)
  • static constructImg ($src, $alt= '', $width= '', $height= '')
    constructor thumbail
  • static checkImg ($src)
    check if image exists and format image is ok
  • static aspectratio ($width_src, $height_src, $max_width= '', $max_height= '')
  • static thumbfile ($image, $width, $height, $width_src, $height_scr, $format)
  • static CleanPathReturn ($img)
    Clean pathname prev return.
  • static thumbgd ($image, $width, $height, $width_src, $height_scr, $format, $thumbfile)
  • static thumbimagick ($image, $width, $height, $format, $thumbfile)

Static Private Attributes

  • static $types = array (1 => "gif", "jpeg", "png")
  • static $env

Detailed Description

Definition at line 12 of file image_ratio.php.


Constructor & Destructor Documentation

image_ratio::__construct (  )  [private]

PHP 5 Constructor.

Definition at line 40 of file image_ratio.php.

00040                                  {
00041 
00042     self::$env = new stdClass();
00043 
00044     self::$env->cachedir = DIR_WS_IMAGES . 'imagecache/';
00045 
00046     umask(0);
00047     if (defined('DIR_WS_ADMIN')){
00048       self::$env->inadmin=true;
00049       !is_dir (DIR_FS_ADMIN.self::$env->cachedir) ? mkdir (DIR_FS_ADMIN.self::$env->cachedir, 0777) : @chmod (DIR_FS_ADMIN.self::$env->cachedir, 0777);
00050     }
00051     else{
00052       self::$env->inadmin=false;
00053     }
00054     !is_dir (DIR_FS_CATALOG.self::$env->cachedir) ? mkdir (DIR_FS_CATALOG.self::$env->cachedir, 0777) : @chmod (DIR_FS_CATALOG.self::$env->cachedir, 0777);
00055 
00056     self::$env->jpegquality = (defined('JPEG_QUALITY') ? JPEG_QUALITY :  95);
00057 
00058     self::$env->safemode=(!ini_get('safe_mode')? true : false );
00059 
00060     self::$env->Imagick=(class_exists('Imagick')? true : false);
00061 
00062     self::$env->img_required=(bool)_cst_bool('IMAGE_REQUIRED');
00063 
00064     self::$env->img_create=(bool)function_exists('imagecreatetruecolor');
00065   }


Member Function Documentation

static image_ratio::aspectratio ( width_src,
height_src,
max_width = '',
max_height = '' 
) [static, private]

Definition at line 251 of file image_ratio.php.

Referenced by constructImg().

00251                                                                                                     {
00252 //     error_reporting(E_ALL);
00253 
00254     !empty ($max_width) && preg_match ('/^[0-9]{1,}$/', $max_width, $regs) && $max_width <= $width_src
00255     ? true
00256     : $max_width = $width_src;
00257     !empty ($max_height) && preg_match ('/^[0-9]{1,}$/', $max_height, $regs) && $max_height <= $height_src
00258     ? true
00259     : $max_height = $height_src;
00260     $width=$max_width;
00261     $height=$max_height;
00262     $width_a=$max_height * $width_src / $height_src;
00263     $height_a=$max_width * $height_src / $width_src;
00264 
00265     if ($max_width == $max_height){
00266       if ($width_src < $height_src){
00267         $width=ceil($max_width * $width_src / $height_src);
00268         $height=$max_width;
00269       }
00270       elseif ($width_src > $height_src) $height=ceil($height_a);
00271       elseif ($width_src == $height_src) $height=$max_width;
00272     }
00273     elseif (($height_a) > $max_height) $width=ceil($width_a);
00274     elseif (($width_a) > $max_width) $height=ceil($height_a);
00275     elseif ($width_src == $height_src){
00276       if ($max_width > $max_height) $width=$max_height;
00277       elseif ($max_width < $max_height) $height=$max_width;
00278     }
00279 
00280     return array("width"=>$width,"height"=>$height);
00281   }

image_ratio::checkImg ( src  )  [static, private]

check if image exists and format image is ok

Parameters:
$src string
$key string cache key for img
Returns:
boolean/string true if ok / false or string error

Definition at line 199 of file image_ratio.php.

Referenced by initCurrent().

00199                                         {
00200 
00201     if(isset(self::$CacheImage[self::$key]['conf']['original'])) return ;
00202 
00203     $sortie=true;
00204 
00205     if(strpos($src, DIR_FS_CATALOG) === false ) $src;
00206     else $src= substr ($src, strlen(DIR_FS_CATALOG));
00207 
00208     if(strpos($src, DIR_WS_LANGUAGES) >0 ) self::$CacheImage[self::$key]['conf']['dest']='lang';
00209     else self::$CacheImage[self::$key]['conf']['dest']='image';
00210 
00211     if (self::$env->inadmin){
00212       self::$CacheImage[self::$key]['conf']['mode']='BO';
00213       if(strpos($src, DIR_WS_ADMIN)===false && strpos($src, DIR_WS_CATALOG)===false && file_exists(DIR_FS_ADMIN.$src)) $src_dir =  $src;
00214       elseif (strpos($src, DIR_WS_ADMIN) >0 || ( strpos($src, DIR_WS_IMAGES) ==0  && file_exists(DIR_FS_ADMIN.$src) ) ) $src_dir = DIR_FS_ADMIN . $src;
00215       elseif(strpos($src, DIR_WS_CATALOG)===false )  $src_dir = DIR_FS_CATALOG . $src;
00216       else $src_dir = DIR_FS_CATALOG . substr ($src, (strrpos (DIR_WS_CATALOG , '/'))+1);
00217     }
00218     else {
00219       self::$CacheImage[self::$key]['conf']['mode']='FO';
00220       $src_dir=$src;
00221     }
00222 
00223     if (!@is_file($src_dir) || empty($src_dir)){
00224       if (self::$env->img_required) $sortie= '<span class="errorText">'.__('Le fichier n\'a pas pu être trouvé sur le serveur !').'</span>';
00225       $sortie = false;
00226     }
00227     elseif ( ($imaged = getimagesize($src_dir)) && is_array($imaged) ) {
00228 
00229       if ( !$imaged[2] || $imaged[2] > 3) {
00230         if (empty($alt)) $sortie= '<span class="errorText">'.__('Ce format d\'image n\'est pas autorisé !').'</span>';
00231         else $sortie ='<span class="errorText" title="'.$src_dir.'">' . tep_output_string($alt) . '!</span>';
00232       }
00233       else self::$CacheImage[self::$key]['conf']['getimagesize']=$imaged;
00234     }
00235 
00236 
00237     if($sortie !=true) self::$CacheImage[self::$key]['conf']['error'] =$sortie;
00238     else  self::$CacheImage[self::$key]['conf']['original'] = $src_dir;
00239   }

static image_ratio::CleanPathReturn ( img  )  [static, private]

Clean pathname prev return.

Parameters:
string pathname

Definition at line 318 of file image_ratio.php.

Referenced by constructImg(), and thumbfile().

00318                                                {
00319 
00320     $ws_=(strpos($img, DIR_WS_CATALOG)===false)?false:true;
00321     $ws_admin=(self::$env->inadmin && strpos($img, DIR_WS_ADMIN)===false )?false:true;
00322     $ws_lg=(strpos($img, DIR_WS_LANGUAGES)===false)?false:true;
00323     $ws_img=(strpos($img, DIR_WS_IMAGES)===false)?false:true;
00324 
00325     $image='';
00326     $mask='';
00327     if(!$ws_admin && $ws_){
00328       $image.=DIR_WS_CATALOG;
00329       $mask .='(.*'.DIR_WS_CATALOG.'){0,1}';
00330     }
00331     if(self::$env->inadmin && $ws_admin) $image.=DIR_WS_ADMIN;
00332     if($ws_lg){
00333       $image.=DIR_WS_LANGUAGES;
00334       $mask .='(.*'.DIR_WS_LANGUAGES.'){0,1}';
00335     }
00336     elseif($ws_img){
00337       $image.=DIR_WS_IMAGES;
00338       $mask .='(.*'.DIR_WS_IMAGES.'){0,1}';
00339     }
00340 
00341     $image.=preg_replace('#'.$mask.'#i','',$img);
00342 
00343     return $image;
00344   }

static image_ratio::constructImg ( src,
alt = '',
width = '',
height = '' 
) [static, private]

constructor thumbail

Parameters:
$src string
$key string cache key for img
$alt string
$width/$height numeric
$parameters string
$mode bool/string (true=url, false=normal, simple= sans width et height)

Definition at line 160 of file image_ratio.php.

Referenced by get_image(), and tep_image().

00160                                                                                   {
00161 
00162     if(isset(self::$CacheImage[self::$key][self::$keydim]) ) return self::$CacheImage[self::$key][self::$keydim];
00163 
00164     $imgd = self::$CacheImage[self::$key]['conf']['getimagesize'];
00165 
00166     $image_size = self::aspectratio($imgd[0], $imgd[1], $width, $height);
00167 
00168     $width = $image_size["width"];
00169     $height = $image_size["height"];
00170 
00171     if (self::$env->img_create && $width !=$imgd[0] && $height != $imgd[1]) {
00172       $src=self::thumbfile($src, $width, $height, $imgd[0], $imgd[1], $imgd[2]);
00173       self::$CacheImage[self::$key][self::$keydim]['thumbfile']='true';
00174     }
00175     else{
00176       $src=self::CleanPathReturn($src);
00177       self::$CacheImage[self::$key][self::$keydim]['thumbfile']='false';
00178     }
00179 
00180 
00181     self::$CacheImage[self::$key][self::$keydim]['src']=$src;
00182     self::$CacheImage[self::$key][self::$keydim]['alt']=$alt;
00183     self::$CacheImage[self::$key][self::$keydim]['width']=$width;
00184     self::$CacheImage[self::$key][self::$keydim]['height']=$height;
00185     self::$CacheImage[self::$key][self::$keydim]['mime']=$imgd['mime'];
00186 
00187 
00188     return self::$CacheImage[self::$key][self::$keydim];
00189   }

static image_ratio::get_image ( src,
alt = '',
width = '',
height = '' 
) [static]

Recup des info d'une image.

Parameters:
$src string
$alt string
$width numeric
$height numeric

Definition at line 134 of file image_ratio.php.

00134                                                                                {
00135     self::getInstance();
00136     self::initCurrent($src,$width,$height);
00137 
00138     if(!isset(self::$CacheImage[self::$key]['conf']['original'])) return self::$CacheImage[self::$key]['conf']['error'];
00139     else $src=self::$CacheImage[self::$key]['conf']['original'];
00140 
00141     return self::constructImg($src, $alt , $width , $height );
00142   }

static image_ratio::getInstance (  )  [static]

Definition at line 67 of file image_ratio.php.

Referenced by get_image(), resetInstance(), tep_image(), and tep_image().

00067                                        {
00068     if(self::$_instance == null)  self::$_instance = new self();
00069     return self::$_instance;
00070   }

static image_ratio::initCurrent ( src,
width,
height 
) [static, private]

Definition at line 144 of file image_ratio.php.

Referenced by get_image(), and tep_image().

00144                                                           {
00145     self::$key = md5($src);
00146     self::$keydim=md5($width . $height);
00147 
00148     self::checkImg($src);
00149   }

static image_ratio::resetInstance (  )  [static]

Definition at line 72 of file image_ratio.php.

00072                                          {
00073     self::$_instance = null;
00074     return self::getInstance();
00075   }

image_ratio::tep_image ( src,
alt = '',
width = '',
height = '',
parameters = '',
mode = false 
) [static]

The HTML image wrapper function.

Parameters:
$src string
$alt string
$width numeric
$height numeric
$parameters string
$mode bool/string (true=url, false=normal, simple= sans width et height)

if cache return

Definition at line 92 of file image_ratio.php.

00092                                                                                                              {
00093     self::getInstance();
00094 
00095     self::initCurrent($src,$width,$height);
00096 
00097     if(!isset(self::$CacheImage[self::$key]['conf']['original'])) return self::$CacheImage[self::$key]['conf']['error'];
00098     else $src=self::$CacheImage[self::$key]['conf']['original'];
00099 
00100     $theImg=self::constructImg($src, $alt , $width , $height );
00101 
00102     $src = $theImg['src'];
00103     $alt = $theImg['alt'];
00104     $width = $theImg['width'];
00105     $height = $theImg['height'];
00106 
00107     if(is_bool($mode) && $mode){
00108       if (self::$env->inadmin)return tep_output_string($src);
00109       return tep_output_string(tep_get_httpdir().$src);
00110     }
00111     else {
00113       if( isset(self::$CacheImage[self::$key][self::$keydim]['img']) ) return self::$CacheImage[self::$key][self::$keydim]['img'];
00114       else {
00115         $image = '<img src="' . (!self::$env->inadmin ? tep_output_string(tep_get_httpdir().$src) : tep_output_string($src)) . '" alt="' . tep_output_string($alt) . '" ';
00116         if($mode !='simple') $image .= 'width="' . $theImg['width'] . '" height="' . $theImg['height'] . '"';
00117         if (tep_not_null($theImg['alt']))  $image .= ' title="' . tep_output_string($theImg['alt']) . '"';
00118         if (tep_not_null($parameters)) $image .= ' ' . $parameters;
00119         $image .= ' />';
00120 
00121         return self::$CacheImage[self::$key][self::$keydim]['img']= $image;
00122       }
00123     }
00124   }

static image_ratio::thumbfile ( image,
width,
height,
width_src,
height_scr,
format 
) [static, private]

Definition at line 283 of file image_ratio.php.

Referenced by constructImg().

00283                                                                                                {
00284 
00285     $thumb = $width.'x'.$height.'_'.basename($image).'_'.md5($image).'.'.((self::$types[$format]=="jpeg") ? "jpg" : self::$types[$format]);
00286 
00287     $thumbfile = substr($image,0, strpos($image, DIR_WS_IMAGES) ) . self::$env->cachedir . $thumb;
00288 
00289     if(isset(self::$CacheImage[self::$key][self::$keydim]['thumbfile_cache'])) $iscached = (bool) self::$CacheImage[self::$key][self::$keydim]['thumbfile_cache'];
00290     else {
00291       if (file_exists ($thumbfile)) {
00292         $thumbdata = getimagesize ($thumbfile);
00293         $iscached =( $thumbdata[0] == $width && $thumbdata[1] == $height )?  true :  false;
00294         if (@filemtime($thumbfile) < @filemtime($image)) $iscached = false;
00295       }
00296       else  $iscached = false;
00297       self::$CacheImage[self::$key][self::$keydim]['thumbfile_cache'] = $iscached;
00298     }
00299 
00300     if (!$iscached)  $makethumb = ($width_src > $width || $height_scr > $height) ?  true : false;
00301     else $makethumb = false;
00302 
00303     if ($makethumb) $image=self::thumbgd($image, $width, $height, $width_src, $height_scr, self::$types[$format], $thumbfile);
00304     else{
00305       $img=($iscached) ? $thumbfile : $image;
00306       $image = self::CleanPathReturn($img);
00307     }
00308 
00309     return $image;
00310   }

static image_ratio::thumbgd ( image,
width,
height,
width_src,
height_scr,
format,
thumbfile 
) [static, private]
Author:
by Christian Lamine, FlashDreams OHG http://www.flashdreams.de/ Modified by http://www.team-noehring.de Modified by http://www.tse.at Modified by lars@iwer.de Traduction Fr : cynic- pour OsCss Modified by oscim for oscss debug + php script Modified by Ayatus
Version:
Thumbnail-Script v1.3 Generating thumbnails 'on-the-fly' with PHP
Note:
This script may be freely used, distribute and modified without any charge as long as this copyright information is included Any commercial selling of this script is forbidden.

Definition at line 362 of file image_ratio.php.

Referenced by thumbfile().

00362                                                                                                          {
00363 //     error_reporting(E_ALL);
00364     $image = call_user_func("imagecreatefrom".$format, $image);
00365     $thumb = imagecreatetruecolor ($width, $height);
00366     imagealphablending($thumb, false);
00367     imagesavealpha($thumb, true);
00368     imagefill($thumb, 0, 0, imagecolorallocatealpha($thumb, 0, 0, 0, 127));
00369     imagecopyresampled ($thumb, $image, 0, 0, 0, 0, $width, $height, $width_src, $height_scr);
00370 
00371     if ($format == "jpeg")  call_user_func("image".$format, $thumb, $thumbfile, self::$env->jpegquality);
00372     else call_user_func("image".$format, $thumb, $thumbfile);
00373     imagedestroy ($image);
00374     imagedestroy ($thumb);
00375 
00376     return $thumbfile;
00377   }

static image_ratio::thumbimagick ( image,
width,
height,
format,
thumbfile 
) [static, private]

Definition at line 380 of file image_ratio.php.

00380                                                                                      {
00381 //     error_reporting(E_ALL);
00382     if (self::$env->Imagick && self::$env->safemod ) {
00383       $thumb = new Imagick($image);
00384         foreach ($thumb as $frame) {
00385           $frame->thumbnailImage($width, $height);
00386           $frame->setImagePage($width, $height, 0, 0);
00387         }
00388       if ($format == "jpeg") {
00389         $thumb->setImageCompression(imagick::COMPRESSION_JPEG);
00390         $thumb->setImageCompressionQuality(self::$env->jpegquality);
00391       }
00392       $thumb->writeImages($thumbfile, true);
00393     }
00394 
00395     return $thumbfile;
00396   }


Member Data Documentation

image_ratio::$_instance [static, protected]

Definition at line 28 of file image_ratio.php.

image_ratio::$CacheImage = array() [static, protected]

Definition at line 24 of file image_ratio.php.

image_ratio::$env [static, private]

Definition at line 36 of file image_ratio.php.

image_ratio::$key [static, protected]

Definition at line 16 of file image_ratio.php.

image_ratio::$keydim [static, protected]

Definition at line 20 of file image_ratio.php.

image_ratio::$types = array (1 => "gif", "jpeg", "png") [static, private]

Definition at line 32 of file image_ratio.php.


The documentation for this class was generated from the following file: