ImageManager
[ class tree: ImageManager ] [ index: ImageManager ] [ all elements ]

Source for file ImageManager.php

Documentation is available at ImageManager.php

  1. <?php
  2. /**
  3.  * ImageManager, list images, directories, and thumbnails.
  4.  * @author $Author: Wei Zhuo $
  5.  * @version $Id: ImageManager.php 27 2004-04-01 08:31:57Z Wei Zhuo $
  6.  * @package ImageManager
  7.  */
  8.  
  9. require_once('Files.php');
  10.  
  11. /**
  12.  * ImageManager Class.
  13.  * @author $Author: Wei Zhuo $
  14.  * @version $Id: ImageManager.php 27 2004-04-01 08:31:57Z Wei Zhuo $
  15.  */
  16. class ImageManager 
  17. {
  18.     /**
  19.      * Configuration array.
  20.      */
  21.     var $config;
  22.  
  23.     /**
  24.      * Array of directory information.
  25.      */
  26.     var $dirs;
  27.  
  28.     /**
  29.      * Constructor. Create a new Image Manager instance.
  30.      * @param array $config configuration array, see config.inc.php
  31.      */
  32.     function ImageManager($config
  33.     {
  34.         $this->config = $config;
  35.     }
  36.  
  37.     /**
  38.      * Get the base directory.
  39.      * @return string base dir, see config.inc.php
  40.      */
  41.     function getBaseDir(
  42.     {
  43.         Return $this->config['base_dir'];
  44.     }
  45.  
  46.     /**
  47.      * Get the base URL.
  48.      * @return string base url, see config.inc.php
  49.      */
  50.     function getBaseURL(
  51.     {
  52.         Return $this->config['base_url'];
  53.     }
  54.  
  55.     function isValidBase()
  56.     {
  57.         return is_dir($this->getBaseDir());
  58.     }
  59.  
  60.     /**
  61.      * Get the tmp file prefix.
  62.      * @return string tmp file prefix.
  63.      */
  64.     function getTmpPrefix(
  65.     {
  66.         Return $this->config['tmp_prefix'];
  67.     }
  68.  
  69.     /**
  70.      * Get the sub directories in the base dir.
  71.      * Each array element contain
  72.      * the relative path (relative to the base dir) as key and the
  73.      * full path as value.
  74.      * @return array of sub directries
  75.      *  <code>array('path name' => 'full directory path', ...)</code>
  76.      */
  77.     function getDirs(
  78.     {
  79.         if(is_null($this->dirs))
  80.         {
  81.             $dirs $this->_dirs($this->getBaseDir(),'/');
  82.             ksort($dirs);
  83.             $this->dirs = $dirs;
  84.         }
  85.         return $this->dirs;
  86.     }
  87.  
  88.     /**
  89.      * Recursively travese the directories to get a list
  90.      * of accessable directories.
  91.      * @param string $base the full path to the current directory
  92.      * @param string $path the relative path name
  93.      * @return array of accessiable sub-directories
  94.      *  <code>array('path name' => 'full directory path', ...)</code>
  95.      */
  96.     function _dirs($base$path
  97.     {
  98.         $base Files::fixPath($base);
  99.         $dirs array();
  100.  
  101.         if($this->isValidBase(== false)
  102.             return $dirs;
  103.  
  104.         $d @dir($base);
  105.         
  106.         while (false !== ($entry $d->read())) 
  107.         {
  108.             //If it is a directory, and it doesn't start with
  109.             // a dot, and if is it not the thumbnail directory
  110.             if(is_dir($base.$entry
  111.                 && substr($entry,0,1!= '.'
  112.                 && $this->isThumbDir($entry== false
  113.             {
  114.                 $relative Files::fixPath($path.$entry);
  115.                 $fullpath Files::fixPath($base.$entry);
  116.                 $dirs[$relative$fullpath;
  117.                 $dirs array_merge($dirs$this->_dirs($fullpath$relative));
  118.             }
  119.         }
  120.         $d->close();
  121.  
  122.         Return $dirs;
  123.     }
  124.  
  125.     /**
  126.      * Get all the files and directories of a relative path.
  127.      * @param string $path relative path to be base path.
  128.      * @return array of file and path information.
  129.      *  <code>array(0=>array('relative'=>'fullpath',...), 1=>array('filename'=>fileinfo array(),...)</code>
  130.      *  fileinfo array: <code>array('url'=>'full url',
  131.      *                        'relative'=>'relative to base',
  132.      *                         'fullpath'=>'full file path',
  133.      *                         'image'=>imageInfo array() false if not image,
  134.      *                         'stat' => filestat)</code>
  135.      */
  136.     function getFiles($path
  137.     {
  138.         $files array();
  139.         $dirs array();
  140.  
  141.         if($this->isValidBase(== false)
  142.             return array($files,$dirs);
  143.  
  144.         $path Files::fixPath($path);
  145.         $base Files::fixPath($this->getBaseDir());
  146.         $fullpath Files::makePath($base,$path);
  147.  
  148.  
  149.         $d @dir($fullpath);
  150.         
  151.         while (false !== ($entry $d->read())) 
  152.         {
  153.             //not a dot file or directory
  154.             if(substr($entry,0,1!= '.')
  155.             {
  156.                 if(is_dir($fullpath.$entry)
  157.                     && $this->isThumbDir($entry== false)
  158.                 {
  159.                     $relative Files::fixPath($path.$entry);
  160.                     $full Files::fixPath($fullpath.$entry);
  161.                     $count $this->countFiles($full);
  162.                     $dirs[$relativearray('fullpath'=>$full,'entry'=>$entry,'count'=>$count);
  163.                 }
  164.                 else if(is_file($fullpath.$entry&& $this->isThumb($entry)==false && $this->isTmpFile($entry== false
  165.                 {
  166.                     $img $this->getImageInfo($fullpath.$entry);
  167.  
  168.                     if(!(!is_array($img)&&$this->config['validate_images']))
  169.                     {
  170.                         $file['url'Files::makePath($this->config['base_url'],$path).$entry;
  171.                         $file['relative'$path.$entry;
  172.                         $file['fullpath'$fullpath.$entry;
  173.                         $file['image'$img;
  174.                         $file['stat'stat($fullpath.$entry);
  175.                         $files[$entry$file;
  176.                     }
  177.                 }
  178.             }
  179.         }
  180.         $d->close();
  181.         ksort($dirs);
  182.         ksort($files);
  183.         
  184.         Return array($dirs$files);
  185.     }    
  186.  
  187.     /**
  188.      * Count the number of files and directories in a given folder
  189.      * minus the thumbnail folders and thumbnails.
  190.      */
  191.     function countFiles($path
  192.     {
  193.         $total 0;
  194.  
  195.         if(is_dir($path)) 
  196.         {
  197.             $d @dir($path);
  198.  
  199.             while (false !== ($entry $d->read())) 
  200.             {
  201.                 //echo $entry."<br>";
  202.                 if(substr($entry,0,1!= '.'
  203.                     && $this->isThumbDir($entry== false
  204.                     && $this->isTmpFile($entry== false
  205.                     && $this->isThumb($entry== false
  206.                 {
  207.                     $total++;
  208.                 }
  209.             }
  210.             $d->close();
  211.         }
  212.         return $total;
  213.     }
  214.  
  215.     /**
  216.      * Get image size information.
  217.      * @param string $file the image file
  218.      * @return array of getImageSize information,
  219.      *   false if the file is not an image.
  220.      */
  221.     function getImageInfo($file
  222.     {
  223.         Return @getImageSize($file);
  224.     }
  225.  
  226.     /**
  227.      * Check if the file contains the thumbnail prefix.
  228.      * @param string $file filename to be checked
  229.      * @return true if the file contains the thumbnail prefix, false otherwise.
  230.      */
  231.     function isThumb($file
  232.     {
  233.         $len strlen($this->config['thumbnail_prefix']);
  234.         if(substr($file,0,$len)==$this->config['thumbnail_prefix'])
  235.             Return true;
  236.         else
  237.             Return false;
  238.     }
  239.  
  240.     /**
  241.      * Check if the given directory is a thumbnail directory.
  242.      * @param string $entry directory name
  243.      * @return true if it is a thumbnail directory, false otherwise
  244.      */
  245.     function isThumbDir($entry
  246.     {
  247.         if($this->config['thumbnail_dir'== false
  248.             || strlen(trim($this->config['thumbnail_dir'])) == 0)
  249.             Return false;        
  250.         else
  251.             Return ($entry == $this->config['thumbnail_dir']);
  252.     }
  253.  
  254.     /**
  255.      * Check if the given file is a tmp file.
  256.      * @param string $file file name
  257.      * @return boolean true if it is a tmp file, false otherwise
  258.      */
  259.     function isTmpFile($file
  260.     {
  261.         $len strlen($this->config['tmp_prefix']);
  262.         if(substr($file,0,$len)==$this->config['tmp_prefix'])
  263.             Return true;
  264.         else
  265.             Return false;         
  266.     }
  267.  
  268.     /**
  269.      * For a given image file, get the respective thumbnail filename
  270.      * no file existence check is done.
  271.      * @param string $fullpathfile the full path to the image file
  272.      * @return string of the thumbnail file
  273.      */
  274.     function getThumbName($fullpathfile
  275.     {
  276.         $path_parts pathinfo($fullpathfile);
  277.         
  278.         $thumbnail $this->config['thumbnail_prefix'].$path_parts['basename'];
  279.  
  280.         if($this->config['safe_mode'== true
  281.             || strlen(trim($this->config['thumbnail_dir'])) == 0)
  282.         {
  283.             Return Files::makeFile($path_parts['dirname'],$thumbnail);
  284.         }
  285.         else
  286.         {
  287.             if(strlen(trim($this->config['thumbnail_dir'])) 0)
  288.             {
  289.                 $path Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
  290.                 if(!is_dir($path))
  291.                     Files::createFolder($path);
  292.                 Return Files::makeFile($path,$thumbnail);
  293.             }
  294.             else //should this ever happen?
  295.             {
  296.                 //error_log('ImageManager: Error in creating thumbnail name');
  297.             }
  298.         }
  299.     }
  300.     
  301.     /**
  302.      * Similar to getThumbName, but returns the URL, base on the
  303.      * given base_url in config.inc.php
  304.      * @param string $relative the relative image file name,
  305.      *  relative to the base_dir path
  306.      * @return string the url of the thumbnail
  307.      */
  308.     function getThumbURL($relative
  309.     {
  310.         $path_parts pathinfo($relative);
  311.         $thumbnail $this->config['thumbnail_prefix'].$path_parts['basename'];
  312.         if($path_parts['dirname']=='\\'$path_parts['dirname']='/';
  313.  
  314.         if($this->config['safe_mode'== true
  315.             || strlen(trim($this->config['thumbnail_dir'])) == 0)
  316.         {
  317.             Return Files::makeFile($this->getBaseURL(),$thumbnail);
  318.         }
  319.         else
  320.         {
  321.             if(strlen(trim($this->config['thumbnail_dir'])) 0)
  322.             {
  323.                 $path Files::makePath($path_parts['dirname'],$this->config['thumbnail_dir']);
  324.                 $url_path Files::makePath($this->getBaseURL()$path);
  325.                 Return Files::makeFile($url_path,$thumbnail);
  326.             }
  327.             else //should this ever happen?
  328.             {
  329.                 //error_log('ImageManager: Error in creating thumbnail url');
  330.             }
  331.  
  332.         }
  333.     }
  334.  
  335.     /**
  336.      * Check if the given path is part of the subdirectories
  337.      * under the base_dir.
  338.      * @param string $path the relative path to be checked
  339.      * @return boolean true if the path exists, false otherwise
  340.      */
  341.     function validRelativePath($path
  342.     {
  343.         $dirs $this->getDirs();
  344.         if($path == '/')
  345.             Return true;
  346.         //check the path given in the url against the 
  347.         //list of paths in the system.
  348.         for($i 0$i count($dirs)$i++)
  349.         {
  350.             $key key($dirs);
  351.             //we found the path
  352.             if($key == $path)
  353.                 Return true;
  354.         
  355.             next($dirs);
  356.         }        
  357.         Return false;
  358.     }
  359.  
  360.     /**
  361.      * Process uploaded files, assumes the file is in
  362.      * $_FILES['upload'] and $_POST['dir'] is set.
  363.      * The dir must be relative to the base_dir and exists.
  364.      * If 'validate_images' is set to true, only file with
  365.      * image dimensions will be accepted.
  366.      * @return null 
  367.      */
  368.     function processUploads(
  369.     {
  370.         if($this->isValidBase(== false)
  371.             return;
  372.  
  373.         $relative null;
  374.  
  375.         if(isset($_POST['dir'])) 
  376.             $relative rawurldecode($_POST['dir']);
  377.         else
  378.             return;
  379.  
  380.         //check for the file, and must have valid relative path
  381.         if(isset($_FILES['upload']&& $this->validRelativePath($relative))
  382.         {
  383.             $upload_result=$this->_processFiles($relative$_FILES['upload']);
  384.             return $upload_result;
  385.         }
  386.     }
  387.     
  388.     /**
  389.      * Insert the uploaded picture in the database.
  390.      * @param string $relative The path in the document images folder
  391.      * @param array $file the uploaded file from $_FILES
  392.      * @param String $file_name the correct file name (generated by the function Files::copyFile).
  393.      */
  394.     function _insertPictureInDatabase($relative$file$file_name){
  395.  
  396.         $image_name=utf8_decode($file_name);
  397.         $image_namestrtr($image_name,"ÀÁÂÃÄÅàáâãäåÒÓÔÕÖØòóôõöøÈÉÊËèéêëÇçÌÍÎÏìíîïÙÚÛÜùúûüÿÑñ","aaaaaaaaaaaaooooooooooooeeeeeeeecciiiiiiiiuuuuuuuuynn");
  398.         $image_name=Files::escape($image_name);
  399.         $image_size=$file["size"];
  400.         
  401.         $path "/images/".substr($relative,1);
  402.  
  403.         include(api_get_path(LIBRARY_PATH)."fileUpload.lib.php");
  404.         
  405.         $doc_id add_document($_course$path.$image_name'file'$image_size$image_name);
  406.         
  407.         api_item_property_update($_courseTOOL_DOCUMENT$doc_id'DocumentCreated'$_user['user_id']);
  408.         
  409.     }
  410.     
  411.     function _deletePictureInDatabase($relative){
  412.         
  413.         $path "/images/".substr($relative,1);
  414.         
  415.         $dbDocumentTable Database::get_course_table(TABLE_DOCUMENT);
  416.         $dbItemPropertyTable Database::get_course_table(TABLE_ITEM_PROPERTY);
  417.         
  418.         //Select the id of the picture to delete
  419.         $sql="SELECT id FROM ".$dbDocumentTable." WHERE path='".$path."'";
  420.         $result=api_sql_query($sql);
  421.         $image_id=mysql_result($result,0,0);
  422.         
  423.         //Delete the picture in the documents table
  424.         $sql="DELETE FROM ".$dbDocumentTable." WHERE id='".$image_id."'";
  425.         $result=api_sql_query($sql);
  426.         
  427.         //Delete the picture in the item_property table
  428.         $sql="DELETE FROM ".$dbItemPropertyTable." WHERE ref='".$image_id."'";
  429.         $result=api_sql_query($sql);
  430.         
  431.     }
  432.     
  433.  
  434.     /**
  435.      * Process upload files. The file must be an
  436.      * uploaded file. If 'validate_images' is set to
  437.      * true, only images will be processed. Any duplicate
  438.      * file will be renamed. See Files::copyFile for details
  439.      * on renaming.
  440.      * @param string $relative the relative path where the file
  441.      *  should be copied to.
  442.      * @param array $file the uploaded file from $_FILES
  443.      * @return boolean true if the file was processed successfully,
  444.      *  false otherwise
  445.      */
  446.     function _processFiles($relative$file)
  447.     {
  448.         if($file['error']!=0)
  449.         {
  450.             Return false;
  451.         }
  452.  
  453.         if(!is_file($file['tmp_name']))
  454.         {
  455.             Return false;
  456.         }
  457.  
  458.         if(!is_uploaded_file($file['tmp_name']))
  459.         {
  460.             Files::delFile($file['tmp_name']);
  461.             Return false;
  462.         }
  463.         
  464.  
  465.         if($this->config['validate_images'== true)
  466.         {
  467.             $imgInfo @getImageSize($file['tmp_name']);
  468.             if(!is_array($imgInfo))
  469.             {
  470.                 Files::delFile($file['tmp_name']);
  471.                 Return false;
  472.             }
  473.         }
  474.  
  475.         //now copy the file
  476.         $path Files::makePath($this->getBaseDir(),$relative);
  477.         $result Files::copyFile($file['tmp_name']$path$file['name']);
  478.  
  479.         //no copy error
  480.         if(!is_int($result))
  481.         {
  482.             Files::delFile($file['tmp_name']);
  483.             
  484.             global $_course;
  485.             //Check if we are in a course context. Otherwise it should mean that we're
  486.             //uploading a file in the generic image upload folder, not into a course, so
  487.             //we don't need to record it into the database.
  488.             //In any case, if $_course['dbName'] is not defined, the database insertion
  489.             //will fail, so we don't loose anything compared to what we have now.
  490.             if(!empty($_course['dbName']))
  491.             {
  492.                 $this->_insertPictureInDatabase($relative$_FILES['upload'],$result);
  493.             }
  494.             
  495.             Return $result;
  496.         }
  497.         
  498.         //delete tmp files.
  499.         Files::delFile($file['tmp_name']);
  500.         Return false;
  501.     }
  502.  
  503.     /**
  504.      * Get the URL of the relative file.
  505.      * basically appends the relative file to the
  506.      * base_url given in config.inc.php
  507.      * @param string $relative a file the relative to the base_dir
  508.      * @return string the URL of the relative file.
  509.      */
  510.     function getFileURL($relative
  511.     {
  512.         Return Files::makeFile($this->getBaseURL(),$relative);
  513.     }
  514.  
  515.     /**
  516.      * Get the fullpath to a relative file.
  517.      * @param string $relative the relative file.
  518.      * @return string the full path, .ie. the base_dir + relative.
  519.      */
  520.     function getFullPath($relative
  521.     {
  522.         Return Files::makeFile($this->getBaseDir(),$relative);;
  523.     }
  524.  
  525.     /**
  526.      * Get the default thumbnail.
  527.      * @return string default thumbnail, empty string if
  528.      *  the thumbnail doesn't exist.
  529.      */
  530.     function getDefaultThumb(
  531.     {
  532.         if(is_file($this->config['default_thumbnail']))
  533.             Return $this->config['default_thumbnail'];
  534.         else 
  535.             Return '';
  536.     }
  537.  
  538.  
  539.     /**
  540.      * Get the thumbnail url to be displayed.
  541.      * If the thumbnail exists, and it is up-to-date
  542.      * the thumbnail url will be returns. If the
  543.      * file is not an image, a default image will be returned.
  544.      * If it is an image file, and no thumbnail exists or
  545.      * the thumbnail is out-of-date (i.e. the thumbnail
  546.      * modified time is less than the original file)
  547.      * then a thumbs.php?img=filename.jpg is returned.
  548.      * The thumbs.php url will generate a new thumbnail
  549.      * on the fly. If the image is less than the dimensions
  550.      * of the thumbnails, the image will be display instead.
  551.      * @param string $relative the relative image file.
  552.      * @return string the url of the thumbnail, be it
  553.      *  actually thumbnail or a script to generate the
  554.      *  thumbnail on the fly.
  555.      */
  556.     function getThumbnail($relative
  557.     {
  558.         $fullpath Files::makeFile($this->getBaseDir(),$relative);
  559.  
  560.         //not a file???
  561.         if(!is_file($fullpath))
  562.             Return $this->getDefaultThumb();
  563.  
  564.         $imgInfo @getImageSize($fullpath);
  565.         
  566.         //not an image
  567.         if(!is_array($imgInfo))
  568.             Return $this->getDefaultThumb();
  569.  
  570.         //the original image is smaller than thumbnails,
  571.         //so just return the url to the original image.
  572.         if ($imgInfo[0<= $this->config['thumbnail_width']
  573.          && $imgInfo[1<= $this->config['thumbnail_height'])
  574.             Return $this->getFileURL($relative);
  575.  
  576.         $thumbnail $this->getThumbName($fullpath);
  577.         
  578.         //check for thumbnails, if exists and
  579.         // it is up-to-date, return the thumbnail url
  580.         if(is_file($thumbnail))
  581.         {
  582.             if(filemtime($thumbnail>= filemtime($fullpath))
  583.                 Return $this->getThumbURL($relative);
  584.         }
  585.  
  586.         //well, no thumbnail was found, so ask the thumbs.php
  587.         //to generate the thumbnail on the fly.
  588.         Return 'thumbs.php?img='.rawurlencode($relative).'&uploadPath='.$_GET['uploadPath'];
  589.     }
  590.  
  591.     /**
  592.      * Delete and specified files.
  593.      * @return boolean true if delete, false otherwise
  594.      */
  595.     function deleteFiles(
  596.     {
  597.         if(!empty($_GET['delf'])){
  598.             $this->_delFile(rawurldecode($_GET['delf']));
  599.             $this->_deletePictureInDatabase(rawurldecode($_GET['delf']));
  600.         }
  601.     }
  602.  
  603.     /**
  604.      * Delete and specified directories.
  605.      * @return boolean true if delete, false otherwise
  606.      */
  607.     function deleteDirs(
  608.     {
  609.          if(isset($_GET['deld']))
  610.             return $this->_delDir(rawurldecode($_GET['deld']));        
  611.          else
  612.              Return false;
  613.     }
  614.  
  615.     /**
  616.      * Delete the relative file, and any thumbnails.
  617.      * @param string $relative the relative file.
  618.      * @return boolean true if deleted, false otherwise.
  619.      */
  620.     function _delFile($relative
  621.     {
  622.         $fullpath Files::makeFile($this->getBaseDir(),$relative);
  623.         
  624.         //check that the file is an image
  625.         if($this->config['validate_images'== true)
  626.         {
  627.             if(!is_array($this->getImageInfo($fullpath)))
  628.                 return false//hmmm not an Image!!???
  629.         }
  630.  
  631.         $thumbnail $this->getThumbName($fullpath);
  632.  
  633.         if(Files::delFile($fullpath))
  634.             Return Files::delFile($thumbnail);
  635.         else
  636.             Return false;
  637.     }
  638.  
  639.     /**
  640.      * Delete directories recursively.
  641.      * @param string $relative the relative path to be deleted.
  642.      * @return boolean true if deleted, false otherwise.
  643.      */
  644.     function _delDir($relative
  645.     {
  646.         $fullpath Files::makePath($this->getBaseDir(),$relative);
  647.         if($this->countFiles($fullpath<= 0)
  648.             return Files::delFolder($fullpath,true)//delete recursively.
  649.         else
  650.             Return false;
  651.     }
  652.  
  653.     /**
  654.      * Create new directories.
  655.      * If in safe_mode, nothing happens.
  656.      * @return boolean true if created, false otherwise.
  657.      */
  658.     function processNewDir(
  659.     {
  660.         if($this->config['safe_mode'== true)
  661.             Return false;
  662.  
  663.         if(isset($_GET['newDir']&& isset($_GET['dir']))
  664.         {
  665.             $newDir rawurldecode($_GET['newDir']);
  666.             $dir rawurldecode($_GET['dir']);
  667.             $path Files::makePath($this->getBaseDir(),$dir);
  668.             $fullpath Files::makePath($pathFiles::escape($newDir));
  669.             if(is_dir($fullpath))
  670.                 Return false;
  671.  
  672.             Return Files::createFolder($fullpath);
  673.         }
  674.     }
  675.  
  676.     /**
  677.      * Do some graphic library method checkings
  678.      * @param string $library the graphics library, GD, NetPBM, or IM.
  679.      * @param string $method the method to check.
  680.      * @return boolean true if able, false otherwise.
  681.      */
  682.     function validGraphicMethods($library,$method)
  683.     {
  684.         switch ($library)
  685.         {
  686.             case 'GD':
  687.                 return $this->_checkGDLibrary($method);
  688.                 break;
  689.             case 'NetPBM':
  690.                 return $this->_checkNetPBMLibrary($method);
  691.                 break;
  692.             case 'IM':
  693.                 return $this->_checkIMLibrary($method);
  694.         }
  695.         return false;
  696.     }
  697.  
  698.     function _checkIMLibrary($method)
  699.     {
  700.         //ImageMagick goes throught 1 single executable
  701.         if(is_file(Files::fixPath(IMAGE_TRANSFORM_LIB_PATH).'convert'))
  702.             return true;
  703.         else
  704.             return false;
  705.     }
  706.  
  707.     /**
  708.      * Check the GD library functionality.
  709.      * @param string $library the graphics library, GD, NetPBM, or IM.
  710.      * @return boolean true if able, false otherwise.
  711.      */
  712.     function _checkGDLibrary($method)
  713.     {
  714.         $errors array();
  715.         switch($method)
  716.         {
  717.             case 'create':
  718.                 $errors['createjpeg'function_exists('imagecreatefromjpeg');
  719.                 $errors['creategif'function_exists('imagecreatefromgif');
  720.                 $errors['createpng'function_exists('imagecreatefrompng');
  721.                 break;
  722.             case 'modify':
  723.                 $errors['create'function_exists('ImageCreateTrueColor'|| function_exists('ImageCreate');
  724.                 $errors['copy'function_exists('ImageCopyResampled'|| function_exists('ImageCopyResized');
  725.                 break;
  726.             case 'save':
  727.                 $errors['savejpeg'function_exists('imagejpeg');
  728.                 $errors['savegif'function_exists('imagegif');
  729.                 $errors['savepng'function_exists('imagepng');
  730.                 break;
  731.         }
  732.  
  733.         return $errors;
  734.     }
  735. }
  736.  
  737. ?>

Documentation generated on Thu, 12 Jun 2008 13:47:00 -0500 by phpDocumentor 1.4.1