Zikula 1.0.1
[ class tree: Zikula 1.0.1 ] [ index: Zikula 1.0.1 ] [ all elements ]

Source for file phpthumb.class.php

Documentation is available at phpthumb.class.php

  1. <?php
  2. //////////////////////////////////////////////////////////////
  3. ///  phpThumb() by James Heinrich <info@silisoftware.com>   //
  4. //        available at http://phpthumb.sourceforge.net     ///
  5. //////////////////////////////////////////////////////////////
  6. ///                                                         //
  7. // See: phpthumb.readme.txt for usage instructions          //
  8. //                                                         ///
  9. //////////////////////////////////////////////////////////////
  10.  
  11. if (!include_once(dirname(__FILE__).'/phpthumb.functions.php')) {
  12.     ob_end_flush();
  13.     die('failed to include_once("'.realpath(dirname(__FILE__).'/phpthumb.functions.php').'")');
  14. }
  15.  
  16. class phpthumb {
  17.  
  18.     // public:
  19.     // START PARAMETERS (for object mode and phpThumb.php)
  20.     // See phpthumb.readme.txt for descriptions of what each of these values are
  21.     var $src  = null;     // SouRCe filename
  22.     var $new  = null;     // NEW image (phpThumb.php only)
  23.     var $w    = null;     // Width
  24.     var $h    = null;     // Height
  25.     var $wp   = null;     // Width  (Portrait Images Only)
  26.     var $hp   = null;     // Height (Portrait Images Only)
  27.     var $wl   = null;     // Width  (Landscape Images Only)
  28.     var $hl   = null;     // Height (Landscape Images Only)
  29.     var $ws   = null;     // Width  (Square Images Only)
  30.     var $hs   = null;     // Height (Square Images Only)
  31.     var $f    = null;     // output image Format
  32.     var $q    = 75;       // jpeg output Quality
  33.     var $sx   = null;     // Source crop top-left X position
  34.     var $sy   = null;     // Source crop top-left Y position
  35.     var $sw   = null;     // Source crop Width
  36.     var $sh   = null;     // Source crop Height
  37.     var $zc   = null;     // Zoom Crop
  38.     var $bc   = null;     // Border Color
  39.     var $bg   = null;     // BackGround color
  40.     var $fltr = array();  // FiLTeRs
  41.     var $goto = null;     // GO TO url after processing
  42.     var $err  = null;     // default ERRor image filename
  43.     var $xto  = null;     // extract eXif Thumbnail Only
  44.     var $ra   = null;     // Rotate by Angle
  45.     var $ar   = null;     // Auto Rotate
  46.     var $aoe  = null;     // Allow Output Enlargement
  47.     var $far  = null;     // Fixed Aspect Ratio
  48.     var $iar  = null;     // Ignore Aspect Ratio
  49.     var $maxb = null;     // MAXimum Bytes
  50.     var $down = null;     // DOWNload thumbnail filename
  51.     var $md5s = null;     // MD5 hash of Source image
  52.     var $sfn  = 0;        // Source Frame Number
  53.     var $dpi  = 150;      // Dots Per Inch for vector source formats
  54.     var $sia  = null;     // Save Image As filename
  55.  
  56.     var $file = null;     // >>>deprecated, DO NOT USE, will be removed in future versions<<<
  57.  
  58.     var $phpThumbDebug = null;
  59.     // END PARAMETERS
  60.  
  61.  
  62.     // public:
  63.     // START CONFIGURATION OPTIONS (for object mode only)
  64.     // See phpThumb.config.php for descriptions of what each of these settings do
  65.  
  66.     // * Directory Configuration
  67.     var $config_cache_directory                      = null;
  68.     var $config_cache_directory_depth                = 0;
  69.     var $config_cache_disable_warning                = true;
  70.     var $config_cache_source_enabled                 = false;
  71.     var $config_cache_source_directory               = null;
  72.     var $config_temp_directory                       = null;
  73.     var $config_document_root                        = null;
  74.  
  75.     // * Default output configuration:
  76.     var $config_output_format                        = 'jpeg';
  77.     var $config_output_maxwidth                      = 0;
  78.     var $config_output_maxheight                     = 0;
  79.     var $config_output_interlace                     = true;
  80.  
  81.     // * Error message configuration
  82.     var $config_error_image_width                    = 400;
  83.     var $config_error_image_height                   = 100;
  84.     var $config_error_message_image_default          = '';
  85.     var $config_error_bgcolor                        = 'CCCCFF';
  86.     var $config_error_textcolor                      = 'FF0000';
  87.     var $config_error_fontsize                       = 1;
  88.     var $config_error_die_on_error                   = false;
  89.     var $config_error_silent_die_on_error            = false;
  90.     var $config_error_die_on_source_failure          = true;
  91.  
  92.     // * Anti-Hotlink Configuration:
  93.     var $config_nohotlink_enabled                    = true;
  94.     var $config_nohotlink_valid_domains              = array();
  95.     var $config_nohotlink_erase_image                = true;
  96.     var $config_nohotlink_text_message               = 'Off-server thumbnailing is not allowed';
  97.     // * Off-server Linking Configuration:
  98.     var $config_nooffsitelink_enabled                = false;
  99.     var $config_nooffsitelink_valid_domains          = array();
  100.     var $config_nooffsitelink_require_refer          = false;
  101.     var $config_nooffsitelink_erase_image            = true;
  102.     var $config_nooffsitelink_watermark_src          = '';
  103.     var $config_nooffsitelink_text_message           = 'Off-server linking is not allowed';
  104.  
  105.     // * Border & Background default colors
  106.     var $config_border_hexcolor                      = '000000';
  107.     var $config_background_hexcolor                  = 'FFFFFF';
  108.  
  109.     // * TrueType Fonts
  110.     var $config_ttf_directory                        = './fonts';
  111.  
  112.     var $config_max_source_pixels                    = null;
  113.     var $config_use_exif_thumbnail_for_speed         = false;
  114.     var $allow_local_http_src                        = false;
  115.  
  116.     var $config_imagemagick_path                     = null;
  117.     var $config_prefer_imagemagick                   = true;
  118.     var $config_imagemagick_use_thumbnail            = true;
  119.  
  120.     var $config_cache_maxage                         = null;
  121.     var $config_cache_maxsize                        = null;
  122.     var $config_cache_maxfiles                       = null;
  123.     var $config_cache_default_only_suffix            = false;
  124.     var $config_cache_force_passthru                 = true;
  125.     var $config_cache_prefix                         = '';    // default value set in the constructor below
  126.  
  127.     // * MySQL
  128.     var $config_mysql_query                          = null;
  129.     var $config_mysql_hostname                       = null;
  130.     var $config_mysql_username                       = null;
  131.     var $config_mysql_password                       = null;
  132.     var $config_mysql_database                       = null;
  133.  
  134.     // * Security
  135.     var $config_high_security_enabled                = false;
  136.     var $config_high_security_password               = null;
  137.     var $config_disable_debug                        = false;
  138.     var $config_allow_src_above_docroot              = false;
  139.     var $config_allow_src_above_phpthumb             = true;
  140.     var $config_allow_parameter_file                 = false;
  141.     var $config_allow_parameter_goto                 = false;
  142.  
  143.     // * HTTP fopen
  144.     var $config_http_fopen_timeout                   = 10;
  145.     var $config_http_follow_redirect                 = true;
  146.  
  147.     // * Compatability
  148.     var $config_disable_pathinfo_parsing             = false;
  149.     var $config_disable_imagecopyresampled           = false;
  150.     var $config_disable_onlycreateable_passthru      = false;
  151.  
  152.     var $config_http_user_agent                      = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7';
  153.  
  154.     // END CONFIGURATION OPTIONS
  155.  
  156.  
  157.     // public: error messages (read-only; persistant)
  158.     var $debugmessages = array();
  159.     var $debugtiming   = array();
  160.     var $fatalerror    = null;
  161.  
  162.  
  163.     // private: (should not be modified directly)
  164.     var $thumbnailQuality = 75;
  165.     var $thumbnailFormat  = null;
  166.  
  167.     var $sourceFilename   = null;
  168.     var $rawImageData     = null;
  169.     var $IMresizedData    = null;
  170.     var $outputImageData  = null;
  171.  
  172.     var $useRawIMoutput   = false;
  173.  
  174.     var $gdimg_output     = null;
  175.     var $gdimg_source     = null;
  176.  
  177.     var $getimagesizeinfo = null;
  178.  
  179.     var $source_width  = null;
  180.     var $source_height = null;
  181.  
  182.     var $thumbnailCropX = null;
  183.     var $thumbnailCropY = null;
  184.     var $thumbnailCropW = null;
  185.     var $thumbnailCropH = null;
  186.  
  187.     var $exif_thumbnail_width  = null;
  188.     var $exif_thumbnail_height = null;
  189.     var $exif_thumbnail_type   = null;
  190.     var $exif_thumbnail_data   = null;
  191.     var $exif_raw_data         = null;
  192.  
  193.     var $thumbnail_width        = null;
  194.     var $thumbnail_height       = null;
  195.     var $thumbnail_image_width  = null;
  196.     var $thumbnail_image_height = null;
  197.  
  198.     var $cache_filename         = null;
  199.  
  200.     var $AlphaCapableFormats = array('png''ico''gif');
  201.     var $is_alpha = false;
  202.  
  203.     var $iswindows = null;
  204.  
  205.     var $phpthumb_version = '1.7.8-200709161750';
  206.  
  207.     //////////////////////////////////////////////////////////////////////
  208.  
  209.     // public: constructor
  210.     function phpThumb({
  211.         $this->DebugTimingMessage('phpThumb() constructor'__FILE____LINE__);
  212.         $this->DebugMessage('phpThumb() v'.$this->phpthumb_version__FILE____LINE__);
  213.         $this->config_max_source_pixels = round(max(intval(ini_get('memory_limit'))intval(get_cfg_var('memory_limit'))) 1048576 0.20)// 20% of memory_limit
  214.         $this->iswindows = (bool) (strtoupper(substr(PHP_OS03)) == 'WIN');
  215.         $this->config_document_root = (@$_SERVER['DOCUMENT_ROOT'$_SERVER['DOCUMENT_ROOT'$this->config_document_root);
  216.         $this->config_cache_prefix = 'phpThumb_cache_'.@$_SERVER['SERVER_NAME'];
  217.  
  218.         $php_sapi_name strtolower(function_exists('php_sapi_name'php_sapi_name('');
  219.         if ($php_sapi_name == 'cli'{
  220.             $this->config_allow_src_above_docroot = true;
  221.         }
  222.     }
  223.  
  224.     // public:
  225.     function setSourceFilename($sourceFilename{
  226.         //$this->resetObject();
  227.         //$this->rawImageData   = null;
  228.         $this->sourceFilename = $sourceFilename;
  229.         $this->src            = $sourceFilename;
  230.         if (is_null($this->config_output_format)) {
  231.             $sourceFileExtension strtolower(substr(strrchr($sourceFilename'.')1));
  232.             if (ereg('^[a-z]{3,4}$'$sourceFileExtension)) {
  233.                 $this->config_output_format = $sourceFileExtension;
  234.                 $this->DebugMessage('setSourceFilename('.$sourceFilename.') set $this->config_output_format to "'.$sourceFileExtension.'"'__FILE____LINE__);
  235.             else {
  236.                 $this->DebugMessage('setSourceFilename('.$sourceFilename.') did NOT set $this->config_output_format to "'.$sourceFileExtension.'" because it did not seem like an appropriate image format'__FILE____LINE__);
  237.             }
  238.         }
  239.         $this->DebugMessage('setSourceFilename('.$sourceFilename.') set $this->sourceFilename to "'.$this->sourceFilename.'"'__FILE____LINE__);
  240.         return true;
  241.     }
  242.  
  243.     // public:
  244.     function setSourceData($rawImageData$sourceFilename=''{
  245.         //$this->resetObject();
  246.         //$this->sourceFilename = null;
  247.         $this->rawImageData   = $rawImageData;
  248.         $this->DebugMessage('setSourceData() setting $this->rawImageData ('.strlen($this->rawImageData).' bytes; magic="'.substr($this->rawImageData04).'" ('.phpthumb_functions::HexCharDisplay(substr($this->rawImageData04)).'))'__FILE____LINE__);
  249.         if ($this->config_cache_source_enabled{
  250.             $sourceFilename ($sourceFilename $sourceFilename md5($rawImageData));
  251.             if (!is_dir($this->config_cache_source_directory)) {
  252.                 $this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not a directory');
  253.             elseif (!@is_writable($this->config_cache_source_directory)) {
  254.                 $this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not writable');
  255.             }
  256.             $this->DebugMessage('setSourceData() attempting to save source image to "'.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename).'"'__FILE____LINE__);
  257.             if ($fp @fopen($this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename)'wb')) {
  258.                 fwrite($fp$rawImageData);
  259.                 fclose($fp);
  260.             elseif (!$this->phpThumbDebug{
  261.                 $this->ErrorImage('setSourceData() failed to write to source cache ('.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode($sourceFilename).')');
  262.             }
  263.         }
  264.         return true;
  265.     }
  266.  
  267.     // public:
  268.     function setSourceImageResource($gdimg{
  269.         //$this->resetObject();
  270.         $this->gdimg_source = $gdimg;
  271.         return true;
  272.     }
  273.  
  274.     // public:
  275.     function setParameter($param$value{
  276.         if ($param == 'src'{
  277.             $this->setSourceFilename($this->ResolveFilenameToAbsolute($value));
  278.         elseif (@is_array($this->$param)) {
  279.             if (is_array($value)) {
  280.                 foreach ($value as $arraykey => $arrayvalue{
  281.                     array_push($this->$param$arrayvalue);
  282.                 }
  283.             else {
  284.                 array_push($this->$param$value);
  285.             }
  286.         else {
  287.             $this->$param $value;
  288.         }
  289.         return true;
  290.     }
  291.  
  292.     // public:
  293.     function getParameter($param{
  294.         //if (property_exists('phpThumb', $param)) {
  295.             return $this->$param;
  296.         //}
  297.         //$this->DebugMessage('setParameter() attempting to get non-existant parameter "'.$param.'"', __FILE__, __LINE__);
  298.         //return false;
  299.     }
  300.  
  301.  
  302.     // public:
  303.     function GenerateThumbnail({
  304.  
  305.         $this->setOutputFormat();
  306.             $this->phpThumbDebug('8a');
  307.         $this->ResolveSource();
  308.             $this->phpThumbDebug('8b');
  309.         $this->SetCacheFilename();
  310.             $this->phpThumbDebug('8c');
  311.         $this->ExtractEXIFgetImageSize();
  312.             $this->phpThumbDebug('8d');
  313.         if ($this->useRawIMoutput{
  314.             $this->DebugMessage('Skipping rest of GenerateThumbnail() because $this->useRawIMoutput'__FILE____LINE__);
  315.             return true;
  316.         }
  317.             $this->phpThumbDebug('8e');
  318.         if (!$this->SourceImageToGD()) {
  319.             $this->DebugMessage('SourceImageToGD() failed'__FILE____LINE__);
  320.             return false;
  321.         }
  322.             $this->phpThumbDebug('8f');
  323.         $this->Rotate();
  324.             $this->phpThumbDebug('8g');
  325.         $this->CreateGDoutput();
  326.             $this->phpThumbDebug('8h');
  327.  
  328.         switch ($this->far{
  329.             case 'L':
  330.             case 'TL':
  331.             case 'BL':
  332.                 $destination_offset_x 0;
  333.                 $destination_offset_y round(($this->thumbnail_height - $this->thumbnail_image_height2);
  334.                 break;
  335.             case 'R':
  336.             case 'TR':
  337.             case 'BR':
  338.                 $destination_offset_x =  round($this->thumbnail_width  - $this->thumbnail_image_width);
  339.                 $destination_offset_y round(($this->thumbnail_height - $this->thumbnail_image_height2);
  340.                 break;
  341.             case 'T':
  342.             case 'TL':
  343.             case 'TR':
  344.                 $destination_offset_x round(($this->thumbnail_width  - $this->thumbnail_image_width)  2);
  345.                 $destination_offset_y 0;
  346.                 break;
  347.             case 'B':
  348.             case 'BL':
  349.             case 'BR':
  350.                 $destination_offset_x round(($this->thumbnail_width  - $this->thumbnail_image_width)  2);
  351.                 $destination_offset_y =  round($this->thumbnail_height - $this->thumbnail_image_height);
  352.                 break;
  353.             case 'C':
  354.             default:
  355.                 $destination_offset_x round(($this->thumbnail_width  - $this->thumbnail_image_width)  2);
  356.                 $destination_offset_y round(($this->thumbnail_height - $this->thumbnail_image_height2);
  357.         }
  358.  
  359. //        // copy/resize image to appropriate dimensions
  360. //        $borderThickness = 0;
  361. //        if (!empty($this->fltr)) {
  362. //            foreach ($this->fltr as $key => $value) {
  363. //                if (ereg('^bord\|([0-9]+)', $value, $matches)) {
  364. //                    $borderThickness = $matches[1];
  365. //                    break;
  366. //                }
  367. //            }
  368. //        }
  369. //        if ($borderThickness > 0) {
  370. //            //$this->DebugMessage('Skipping ImageResizeFunction() because BorderThickness="'.$borderThickness.'"', __FILE__, __LINE__);
  371. //            $this->thumbnail_image_height /= 2;
  372. //        }
  373.         $this->ImageResizeFunction(
  374.             $this->gdimg_output,
  375.             $this->gdimg_source,
  376.             $destination_offset_x,
  377.             $destination_offset_y,
  378.             $this->thumbnailCropX,
  379.             $this->thumbnailCropY,
  380.             $this->thumbnail_image_width,
  381.             $this->thumbnail_image_height,
  382.             $this->thumbnailCropW,
  383.             $this->thumbnailCropH
  384.         );
  385.  
  386.         $this->DebugMessage('memory_get_usage() after copy-resize = '.(function_exists('memory_get_usage'@memory_get_usage('n/a')__FILE____LINE__);
  387.         ImageDestroy($this->gdimg_source);
  388.         $this->DebugMessage('memory_get_usage() after ImageDestroy = '.(function_exists('memory_get_usage'@memory_get_usage('n/a')__FILE____LINE__);
  389.  
  390.             $this->phpThumbDebug('8i');
  391.         $this->AntiOffsiteLinking();
  392.             $this->phpThumbDebug('8j');
  393.         $this->ApplyFilters();
  394.             $this->phpThumbDebug('8k');
  395.         $this->AlphaChannelFlatten();
  396.             $this->phpThumbDebug('8l');
  397.         $this->MaxFileSize();
  398.             $this->phpThumbDebug('8m');
  399.  
  400.         $this->DebugMessage('GenerateThumbnail() completed successfully'__FILE____LINE__);
  401.         return true;
  402.     }
  403.  
  404.  
  405.     // public:
  406.     function RenderOutput({
  407.         if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
  408.             $this->DebugMessage('RenderOutput() failed because !is_resource($this->gdimg_output)'__FILE____LINE__);
  409.             return false;
  410.         }
  411.         if (!$this->thumbnailFormat{
  412.             $this->DebugMessage('RenderOutput() failed because $this->thumbnailFormat is empty'__FILE____LINE__);
  413.             return false;
  414.         }
  415.         if ($this->useRawIMoutput{
  416.             $this->DebugMessage('RenderOutput copying $this->IMresizedData ('.strlen($this->IMresizedData).' bytes) to $this->outputImage'__FILE____LINE__);
  417.             $this->outputImageData = $this->IMresizedData;
  418.             return true;
  419.         }
  420.  
  421.         $builtin_formats array();
  422.         if (function_exists('ImageTypes')) {
  423.             $imagetypes ImageTypes();
  424.             $builtin_formats['wbmp'= (bool) ($imagetypes IMG_WBMP);
  425.             $builtin_formats['jpg']  = (bool) ($imagetypes IMG_JPG);
  426.             $builtin_formats['gif']  = (bool) ($imagetypes IMG_GIF);
  427.             $builtin_formats['png']  = (bool) ($imagetypes IMG_PNG);
  428.         }
  429.         $this->DebugMessage('RenderOutput() attempting Image'.strtoupper(@$this->thumbnailFormat).'($this->gdimg_output)'__FILE____LINE__);
  430.         ob_start();
  431.         switch ($this->thumbnailFormat{
  432.             case 'wbmp':
  433.                 if (!@$builtin_formats['wbmp']{
  434.                     $this->DebugMessage('GD does not have required built-in support for WBMP output'__FILE____LINE__);
  435.                     ob_end_clean();
  436.                     return false;
  437.                 }
  438.                 ImageJPEG($this->gdimg_outputnull$this->thumbnailQuality);
  439.                 $this->outputImageData = ob_get_contents();
  440.                 break;
  441.  
  442.             case 'jpeg':
  443.             case 'jpg':  // should be "jpeg" not "jpg" but just in case...
  444.                 if (!@$builtin_formats['jpg']{
  445.                     $this->DebugMessage('GD does not have required built-in support for JPEG output'__FILE____LINE__);
  446.                     ob_end_clean();
  447.                     return false;
  448.                 }
  449.                 ImageJPEG($this->gdimg_outputnull$this->thumbnailQuality);
  450.                 $this->outputImageData = ob_get_contents();
  451.                 break;
  452.  
  453.             case 'png':
  454.                 if (!@$builtin_formats['png']{
  455.                     $this->DebugMessage('GD does not have required built-in support for PNG output'__FILE____LINE__);
  456.                     ob_end_clean();
  457.                     return false;
  458.                 }
  459.                 ImagePNG($this->gdimg_output);
  460.                 $this->outputImageData = ob_get_contents();
  461.                 break;
  462.  
  463.             case 'gif':
  464.                 if (!@$builtin_formats['gif']{
  465.                     $this->DebugMessage('GD does not have required built-in support for GIF output'__FILE____LINE__);
  466.                     ob_end_clean();
  467.                     return false;
  468.                 }
  469.                 ImageGIF($this->gdimg_output);
  470.                 $this->outputImageData = ob_get_contents();
  471.                 break;
  472.  
  473.             case 'bmp':
  474.                 $ImageOutFunction '"builtin BMP output"';
  475.                 if (!@include_once(dirname(__FILE__).'/phpthumb.bmp.php')) {
  476.                     $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.bmp.php" which is required for BMP format output'__FILE____LINE__);
  477.                     ob_end_clean();
  478.                     return false;
  479.                 }
  480.                 $phpthumb_bmp new phpthumb_bmp();
  481.                 $this->outputImageData = $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
  482.                 unset($phpthumb_bmp);
  483.                 break;
  484.  
  485.             case 'ico':
  486.                 $ImageOutFunction '"builtin ICO output"';
  487.                 if (!@include_once(dirname(__FILE__).'/phpthumb.ico.php')) {
  488.                     $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.ico.php" which is required for ICO format output'__FILE____LINE__);
  489.                     ob_end_clean();
  490.                     return false;
  491.                 }
  492.                 $phpthumb_ico new phpthumb_ico();
  493.                 $arrayOfOutputImages array($this->gdimg_output);
  494.                 $this->outputImageData = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
  495.                 unset($phpthumb_ico);
  496.                 break;
  497.  
  498.             default:
  499.                 $this->DebugMessage('RenderOutput failed because $this->thumbnailFormat "'.$this->thumbnailFormat.'" is not valid'__FILE____LINE__);
  500.                 ob_end_clean();
  501.                 return false;
  502.         }
  503.         ob_end_clean();
  504.         if (!$this->outputImageData{
  505.             $this->DebugMessage('RenderOutput() for "'.$this->thumbnailFormat.'" failed'__FILE____LINE__);
  506.             ob_end_clean();
  507.             return false;
  508.         }
  509.         $this->DebugMessage('RenderOutput() completing with $this->outputImageData = '.strlen($this->outputImageData).' bytes'__FILE____LINE__);
  510.         return true;
  511.     }
  512.  
  513.  
  514.     // public:
  515.     function RenderToFile($filename{
  516.         if (eregi('^(f|ht)tps?\://'$filename)) {
  517.             $this->DebugMessage('RenderToFile() failed because $filename ('.$filename.') is a URL'__FILE____LINE__);
  518.             return false;
  519.         }
  520.         // render thumbnail to this file only, do not cache, do not output to browser
  521.         //$renderfilename = $this->ResolveFilenameToAbsolute(dirname($filename)).DIRECTORY_SEPARATOR.basename($filename);
  522.         $renderfilename $filename;
  523.         if (($filename{0!= '/'&& ($filename{0!= '\\'&& ($filename{1!= ':')) {
  524.             $renderfilename $this->ResolveFilenameToAbsolute($renderfilename);
  525.         }
  526.         if (!@is_writable(dirname($renderfilename))) {
  527.             $this->DebugMessage('RenderToFile() failed because "'.dirname($renderfilename).'/" is not writable'__FILE____LINE__);
  528.             return false;
  529.         }
  530.         if (@is_file($renderfilename&& !@is_writable($renderfilename)) {
  531.             $this->DebugMessage('RenderToFile() failed because "'.$renderfilename.'" is not writable'__FILE____LINE__);
  532.             return false;
  533.         }
  534.  
  535.         if ($this->RenderOutput()) {
  536.             if (file_put_contents($renderfilename$this->outputImageData)) {
  537.                 $this->DebugMessage('RenderToFile('.$renderfilename.') succeeded'__FILE____LINE__);
  538.                 return true;
  539.             }
  540.             if (!@file_exists($renderfilename)) {
  541.                 $this->DebugMessage('RenderOutput ['.$this->thumbnailFormat.'('.$renderfilename.')] did not appear to fail, but the output image does not exist either...'__FILE____LINE__);
  542.             }
  543.         else {
  544.             $this->DebugMessage('RenderOutput ['.$this->thumbnailFormat.'('.$renderfilename.')] failed'__FILE____LINE__);
  545.         }
  546.         return false;
  547.     }
  548.  
  549.  
  550.     // public:
  551.     function OutputThumbnail({
  552.         if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
  553.             $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)'__FILE____LINE__);
  554.             return false;
  555.         }
  556.         if (headers_sent()) {
  557.             return $this->ErrorImage('OutputThumbnail() failed - headers already sent');
  558.             exit;
  559.         }
  560.  
  561.         $downloadfilename phpthumb_functions::SanitizeFilename(is_string($this->sia$this->sia : ($this->down ? $this->down : 'phpThumb_generated_thumbnail'.'.'.$this->thumbnailFormat));
  562.         $this->DebugMessage('Content-Disposition header filename set to "'.$downloadfilename.'"'__FILE____LINE__);
  563.         if ($downloadfilename{
  564.             header('Content-Disposition: '.($this->down ? 'attachment' 'inline').'; filename="'.$downloadfilename.'"');
  565.         else {
  566.             $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty'__FILE____LINE__);
  567.         }
  568.  
  569.         if ($this->useRawIMoutput{
  570.  
  571.             header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
  572.             echo $this->IMresizedData;
  573.  
  574.         else {
  575.  
  576.             $this->DebugMessage('ImageInterlace($this->gdimg_output, '.intval($this->config_output_interlace).')'__FILE____LINE__);
  577.             ImageInterlace($this->gdimg_outputintval($this->config_output_interlace));
  578.             switch ($this->thumbnailFormat{
  579.                 case 'jpeg':
  580.                     header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
  581.                     $ImageOutFunction 'image'.$this->thumbnailFormat;
  582.                     @$ImageOutFunction($this->gdimg_output''$this->thumbnailQuality);
  583.                     break;
  584.  
  585.                 case 'png':
  586.                 case 'gif':
  587.                     header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
  588.                     $ImageOutFunction 'image'.$this->thumbnailFormat;
  589.                     @$ImageOutFunction($this->gdimg_output);
  590.                     break;
  591.  
  592.                 case 'bmp':
  593.                     if (!@include_once(dirname(__FILE__).'/phpthumb.bmp.php')) {
  594.                         $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.bmp.php" which is required for BMP format output'__FILE____LINE__);
  595.                         return false;
  596.                     }
  597.                     $phpthumb_bmp new phpthumb_bmp();
  598.                     if (is_object($phpthumb_bmp)) {
  599.                         $bmp_data $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
  600.                         unset($phpthumb_bmp);
  601.                         if (!$bmp_data{
  602.                             $this->DebugMessage('$phpthumb_bmp->GD2BMPstring() failed'__FILE____LINE__);
  603.                             return false;
  604.                         }
  605.                         header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
  606.                         echo $bmp_data;
  607.                     else {
  608.                         $this->DebugMessage('new phpthumb_bmp() failed'__FILE____LINE__);
  609.                         return false;
  610.                     }
  611.                     break;
  612.  
  613.                 case 'ico':
  614.                     if (!@include_once(dirname(__FILE__).'/phpthumb.ico.php')) {
  615.                         $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.ico.php" which is required for ICO format output'__FILE____LINE__);
  616.                         return false;
  617.                     }
  618.                     $phpthumb_ico new phpthumb_ico();
  619.                     if (is_object($phpthumb_ico)) {
  620.                         $arrayOfOutputImages array($this->gdimg_output);
  621.                         $ico_data $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
  622.                         unset($phpthumb_ico);
  623.                         if (!$ico_data{
  624.                             $this->DebugMessage('$phpthumb_ico->GD2ICOstring() failed'__FILE____LINE__);
  625.                             return false;
  626.                         }
  627.                         header('Content-Type: '.phpthumb_functions::ImageTypeToMIMEtype($this->thumbnailFormat));
  628.                         echo $ico_data;
  629.                     else {
  630.                         $this->DebugMessage('new phpthumb_ico() failed'__FILE____LINE__);
  631.                         return false;
  632.                     }
  633.                     break;
  634.  
  635.                 default:
  636.                     $this->DebugMessage('OutputThumbnail failed because $this->thumbnailFormat "'.$this->thumbnailFormat.'" is not valid'__FILE____LINE__);
  637.                     return false;
  638.                     break;
  639.             }
  640.  
  641.         }
  642.         return true;
  643.     }
  644.  
  645.  
  646.     // public:
  647.     function CleanUpCacheDirectory({
  648.         $this->DebugMessage('skipping CleanUpCacheDirectory() set to purge ('.number_format($this->config_cache_maxage / 864001).' days; '.number_format($this->config_cache_maxsize / 10485762).'MB; '.number_format($this->config_cache_maxfiles).' files)'__FILE____LINE__);
  649.         if (($this->config_cache_maxage > 0|| ($this->config_cache_maxsize > 0|| ($this->config_cache_maxfiles > 0)) {
  650.             $CacheDirOldFilesAge  array();
  651.             $CacheDirOldFilesSize array();
  652.             $AllFilesInCacheDirectory phpthumb_functions::GetAllFilesInSubfolders($this->config_cache_directory);
  653.             foreach ($AllFilesInCacheDirectory as $fullfilename{
  654.                 if (eregi('^phpThumb_cache_'basename($fullfilename)) && file_exists($fullfilename)) {
  655.                     $CacheDirOldFilesAge[$fullfilename@fileatime($fullfilename);
  656.                     if ($CacheDirOldFilesAge[$fullfilename== 0{
  657.                         $CacheDirOldFilesAge[$fullfilename@filemtime($fullfilename);
  658.                     }
  659.                     $CacheDirOldFilesSize[$fullfilename@filesize($fullfilename);
  660.                 }
  661.             }
  662.             if (empty($CacheDirOldFilesSize)) {
  663.                 return true;
  664.             }
  665.             $DeletedKeys['zerobyte'array();
  666.             foreach ($CacheDirOldFilesSize as $fullfilename => $filesize{
  667.                 // purge all zero-size files more than an hour old (to prevent trying to delete just-created and/or in-use files)
  668.                 $cutofftime time(3600;
  669.                 if (($filesize == 0&& ($CacheDirOldFilesAge[$fullfilename$cutofftime)) {
  670.                     if (@unlink($fullfilename)) {
  671.                         $DeletedKeys['zerobyte'][$fullfilename;
  672.                         unset($CacheDirOldFilesSize[$fullfilename]);
  673.                         unset($CacheDirOldFilesAge[$fullfilename]);
  674.                     }
  675.                 }
  676.             }
  677.             $this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['zerobyte']).' zero-byte files'__FILE____LINE__);
  678.             asort($CacheDirOldFilesAge);
  679.  
  680.             if ($this->config_cache_maxfiles > 0{
  681.                 $TotalCachedFiles count($CacheDirOldFilesAge);
  682.                 $DeletedKeys['maxfiles'array();
  683.                 foreach ($CacheDirOldFilesAge as $fullfilename => $filedate{
  684.                     if ($TotalCachedFiles $this->config_cache_maxfiles{
  685.                         if (@unlink($fullfilename)) {
  686.                             $TotalCachedFiles--;
  687.                             $DeletedKeys['maxfiles'][$fullfilename;
  688.                         }
  689.                     else {
  690.                         // there are few enough files to keep the rest
  691.                         break;
  692.                     }
  693.                 }
  694.                 $this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['maxfiles']).' files based on (config_cache_maxfiles='.$this->config_cache_maxfiles.')'__FILE____LINE__);
  695.                 foreach ($DeletedKeys['maxfiles'as $fullfilename{
  696.                     unset($CacheDirOldFilesAge[$fullfilename]);
  697.                     unset($CacheDirOldFilesSize[$fullfilename]);
  698.                 }
  699.             }
  700.  
  701.             if ($this->config_cache_maxage > 0{
  702.                 $mindate time($this->config_cache_maxage;
  703.                 $DeletedKeys['maxage'array();
  704.                 foreach ($CacheDirOldFilesAge as $fullfilename => $filedate{
  705.                     if ($filedate 0{
  706.                         if ($filedate $mindate{
  707.                             if (@unlink($fullfilename)) {
  708.                                 $DeletedKeys['maxage'][$fullfilename;
  709.                             }
  710.                         else {
  711.                             // the rest of the files are new enough to keep
  712.                             break;
  713.                         }
  714.                     }
  715.                 }
  716.                 $this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['maxage']).' files based on (config_cache_maxage='.$this->config_cache_maxage.')'__FILE____LINE__);
  717.                 foreach ($DeletedKeys['maxage'as $fullfilename{
  718.                     unset($CacheDirOldFilesAge[$fullfilename]);
  719.                     unset($CacheDirOldFilesSize[$fullfilename]);
  720.                 }
  721.             }
  722.  
  723.             if ($this->config_cache_maxsize > 0{
  724.                 $TotalCachedFileSize array_sum($CacheDirOldFilesSize);
  725.                 $DeletedKeys['maxsize'array();
  726.                 foreach ($CacheDirOldFilesAge as $fullfilename => $filedate{
  727.                     if ($TotalCachedFileSize $this->config_cache_maxsize{
  728.                         if (@unlink($fullfilename)) {
  729.                             $TotalCachedFileSize -= $CacheDirOldFilesSize[$fullfilename];
  730.                             $DeletedKeys['maxsize'][$fullfilename;
  731.                         }
  732.                     else {
  733.                         // the total filesizes are small enough to keep the rest of the files
  734.                         break;
  735.                     }
  736.                 }
  737.                 $this->DebugMessage('CleanUpCacheDirectory() purged '.count($DeletedKeys['maxsize']).' files based on (config_cache_maxsize='.$this->config_cache_maxsize.')'__FILE____LINE__);
  738.                 foreach ($DeletedKeys['maxsize'as $fullfilename{
  739.                     unset($CacheDirOldFilesAge[$fullfilename]);
  740.                     unset($CacheDirOldFilesSize[$fullfilename]);
  741.                 }
  742.             }
  743.  
  744.         else {
  745.             $this->DebugMessage('skipping CleanUpCacheDirectory() because config set to not use it'__FILE____LINE__);
  746.         }
  747.         $totalpurged 0;
  748.         foreach ($DeletedKeys as $key => $value{
  749.             $totalpurged += count($value);
  750.         }
  751.         $this->DebugMessage('CleanUpCacheDirectory() purged '.$totalpurged.' files (from '.count($AllFilesInCacheDirectory).') based on config settings'__FILE____LINE__);
  752.         if ($totalpurged 0{
  753.             $empty_dirs array();
  754.             foreach ($AllFilesInCacheDirectory as $fullfilename{
  755.                 if (is_dir($fullfilename)) {
  756.                     $empty_dirs[realpath($fullfilename)1;
  757.                 else {
  758.                     unset($empty_dirs[realpath(dirname($fullfilename))]);
  759.                 }
  760.             }
  761.             krsort($empty_dirs);
  762.             $totalpurgeddirs 0;
  763.             foreach ($empty_dirs as $empty_dir => $dummy{
  764.                 if ($empty_dir == $this->config_cache_directory{
  765.                     // shouldn't happen, but just in case, don't let it delete actual cache directory
  766.                     continue;
  767.                 elseif (@rmdir($empty_dir)) {
  768.                     $totalpurgeddirs++;
  769.                 else {
  770.                     $this->DebugMessage('failed to rmdir('.$empty_dir.')'__FILE____LINE__);
  771.                 }
  772.             }
  773.             $this->DebugMessage('purged '.$totalpurgeddirs.' empty directories'__FILE____LINE__);
  774.         }
  775.         return true;
  776.     }
  777.  
  778.     //////////////////////////////////////////////////////////////////////
  779.  
  780.     // private: re-initializator (call between rendering multiple images with one object)
  781.     function resetObject({
  782.         $class_vars get_class_vars(get_class($this));
  783.         foreach ($class_vars as $key => $value{
  784.             // do not clobber debug or config info
  785.             if (!eregi('^(config_|debug|fatalerror)'$key)) {
  786.                 $this->$key $value;
  787.             }
  788.         }
  789.         $this->phpThumb()// re-initialize some class variables
  790.         return true;
  791.     }
  792.  
  793.     //////////////////////////////////////////////////////////////////////
  794.  
  795.     function ResolveSource({
  796.         if (is_resource($this->gdimg_source)) {
  797.             $this->DebugMessage('ResolveSource() exiting because is_resource($this->gdimg_source)'__FILE____LINE__);
  798.             return true;
  799.         }
  800.         if ($this->rawImageData{
  801.             $this->sourceFilename = null;
  802.             $this->DebugMessage('ResolveSource() exiting because $this->rawImageData is set ('.number_format(strlen($this->rawImageData)).' bytes)'__FILE____LINE__);
  803.             return true;
  804.         }
  805.         if ($this->sourceFilename{
  806.             $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->sourceFilename);
  807.             $this->DebugMessage('$this->sourceFilename set to "'.$this->sourceFilename.'"'__FILE____LINE__);
  808.         elseif ($this->src{
  809.             $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->src);
  810.             $this->DebugMessage('$this->sourceFilename set to "'.$this->sourceFilename.'" from $this->src ('.$this->src.')'__FILE____LINE__);
  811.         else {
  812.             return $this->ErrorImage('$this->sourceFilename and $this->src are both empty');
  813.         }
  814.         if ($this->iswindows && ((substr($this->sourceFilename02== '//'|| (substr($this->sourceFilename02== '\\\\'))) {
  815.             // Windows \\share\filename.ext
  816.         elseif (eregi('^(f|ht)tps?\://'$this->sourceFilename)) {
  817.             // URL
  818.             if ($this->config_http_user_agent{
  819.                 ini_set('user_agent'$this->config_http_user_agent);
  820.             }
  821.         elseif (!@file_exists($this->sourceFilename)) {
  822.             return $this->ErrorImage('"'.$this->sourceFilename.'" does not exist');
  823.         elseif (!@is_file($this->sourceFilename)) {
  824.             return $this->ErrorImage('"'.$this->sourceFilename.'" is not a file');
  825.         }
  826.         return true;
  827.     }
  828.  
  829.     function setOutputFormat({
  830.         static $alreadyCalled false;
  831.         if ($this->thumbnailFormat && $alreadyCalled{
  832.             return true;
  833.         }
  834.         $alreadyCalled true;
  835.  
  836.         $AvailableImageOutputFormats array();
  837.         $AvailableImageOutputFormats['text';
  838.         if (@is_readable(dirname(__FILE__).'/phpthumb.ico.php')) {
  839.             $AvailableImageOutputFormats['ico';
  840.         }
  841.         if (@is_readable(dirname(__FILE__).'/phpthumb.bmp.php')) {
  842.             $AvailableImageOutputFormats['bmp';
  843.         }
  844.  
  845.         $this->thumbnailFormat 'ico';
  846.  
  847.         // Set default output format based on what image types are available
  848.         if (function_exists('ImageTypes')) {
  849.             $imagetypes ImageTypes();
  850.             if ($imagetypes IMG_WBMP{
  851.                 $this->thumbnailFormat         'wbmp';
  852.                 $AvailableImageOutputFormats['wbmp';
  853.             }
  854.             if ($imagetypes IMG_GIF{
  855.                 $this->thumbnailFormat         'gif';
  856.                 $AvailableImageOutputFormats['gif';
  857.             }
  858.             if ($imagetypes IMG_PNG{
  859.                 $this->thumbnailFormat         'png';
  860.                 $AvailableImageOutputFormats['png';
  861.             }
  862.             if ($imagetypes IMG_JPG{
  863.                 $this->thumbnailFormat         'jpeg';
  864.                 $AvailableImageOutputFormats['jpeg';
  865.             }
  866.         else {
  867.             //return $this->ErrorImage('ImageTypes() does not exist - GD support might not be enabled?');
  868.             $this->DebugMessage('ImageTypes() does not exist - GD support might not be enabled?',  __FILE____LINE__);
  869.         }
  870.         if ($this->ImageMagickVersion()) {
  871.             $IMformats array('jpeg''png''gif''bmp''ico''wbmp');
  872.             $this->DebugMessage('Addding ImageMagick formats to $AvailableImageOutputFormats ('.implode(';'$AvailableImageOutputFormats).')'__FILE____LINE__);
  873.             foreach ($IMformats as $key => $format{
  874.                 $AvailableImageOutputFormats[$format;
  875.             }
  876.         }
  877.         $AvailableImageOutputFormats array_unique($AvailableImageOutputFormats);
  878.         $this->DebugMessage('$AvailableImageOutputFormats = array('.implode(';'$AvailableImageOutputFormats).')'__FILE____LINE__);
  879.  
  880.         $this->f ereg_replace('[^a-z]'''strtolower($this->f));
  881.         if (strtolower($this->config_output_format== 'jpg'{
  882.             $this->config_output_format 'jpeg';
  883.         }
  884.         if (strtolower($this->f== 'jpg'{
  885.             $this->f 'jpeg';
  886.         }
  887.         if (phpthumb_functions::CaseInsensitiveInArray($this->config_output_format$AvailableImageOutputFormats)) {
  888.             // set output format to config default if that format is available
  889.             $this->DebugMessage('$this->thumbnailFormat set to $this->config_output_format "'.strtolower($this->config_output_format).'"'__FILE____LINE__);
  890.             $this->thumbnailFormat strtolower($this->config_output_format);
  891.         elseif ($this->config_output_format{
  892.             $this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because $this->config_output_format ('.strtolower($this->config_output_format).') is not in $AvailableImageOutputFormats'__FILE____LINE__);
  893.         }
  894.         if ($this->f && (phpthumb_functions::CaseInsensitiveInArray($this->f$AvailableImageOutputFormats))) {
  895.             // override output format if $this->f is set and that format is available
  896.             $this->DebugMessage('$this->thumbnailFormat set to $this->f "'.strtolower($this->f).'"'__FILE____LINE__);
  897.             $this->thumbnailFormat strtolower($this->f);
  898.         elseif ($this->f{
  899.             $this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because $this->f ('.strtolower($this->f).') is not in $AvailableImageOutputFormats'__FILE____LINE__);
  900.         }
  901.  
  902.         // for JPEG images, quality 1 (worst) to 99 (best)
  903.         // quality < 25 is nasty, with not much size savings - not recommended
  904.         // problems with 100 - invalid JPEG?
  905.         $this->thumbnailQuality max(1min(99($this->q $this->q 75)));
  906.         $this->DebugMessage('$this->thumbnailQuality set to "'.$this->thumbnailQuality.'"'__FILE____LINE__);
  907.  
  908.         return true;
  909.     }
  910.  
  911.     function setCacheDirectory({
  912.         // resolve cache directory to absolute pathname
  913.         $this->DebugMessage('setCacheDirectory() starting with config_cache_directory = "'.$this->config_cache_directory.'"'__FILE____LINE__);
  914.         if (substr($this->config_cache_directory01== '.'{
  915.             if (eregi('^(f|ht)tps?\://'$this->src)) {
  916.                 if (!$this->config_cache_disable_warning{
  917.                     $this->ErrorImage('$this->config_cache_directory ('.$this->config_cache_directory.') cannot be used for remote images. Adjust "cache_directory" or "cache_disable_warning" in phpThumb.config.php');
  918.                 }
  919.             elseif ($this->src{
  920.                 // resolve relative cache directory to source image
  921.                 $this->config_cache_directory dirname($this->ResolveFilenameToAbsolute($this->src)).DIRECTORY_SEPARATOR.$this->config_cache_directory;
  922.             else {
  923.                 // $this->new is probably set
  924.             }
  925.         }
  926.         if (substr($this->config_cache_directory-1== '/'{
  927.             $this->config_cache_directory substr($this->config_cache_directory0-1);
  928.         }
  929.         if ($this->iswindows{
  930.             $this->config_cache_directory str_replace('/'DIRECTORY_SEPARATOR$this->config_cache_directory);
  931.         }
  932.         if ($this->config_cache_directory{
  933.             $real_cache_path realpath($this->config_cache_directory);
  934.             if (!$real_cache_path{
  935.                 $this->DebugMessage('realpath($this->config_cache_directory) failed for "'.$this->config_cache_directory.'"'__FILE____LINE__);
  936.                 if (!is_dir($this->config_cache_directory)) {
  937.                     $this->DebugMessage('!is_dir('.$this->config_cache_directory.')'__FILE____LINE__);
  938.                 }
  939.             }
  940.             if ($real_cache_path{
  941.                 $this->DebugMessage('setting config_cache_directory to realpath('.$this->config_cache_directory.') = "'.$real_cache_path.'"'__FILE____LINE__);
  942.                 $this->config_cache_directory $real_cache_path;
  943.             }
  944.         }
  945.         if (!is_dir($this->config_cache_directory)) {
  946.             if (!$this->config_cache_disable_warning{
  947.                 $this->ErrorImage('$this->config_cache_directory ('.$this->config_cache_directory.') does not exist. Adjust "cache_directory" or "cache_disable_warning" in phpThumb.config.php');
  948.             }
  949.             $this->DebugMessage('$this->config_cache_directory ('.$this->config_cache_directory.') is not a directory'__FILE____LINE__);
  950.             $this->config_cache_directory null;
  951.         elseif (!@is_writable($this->config_cache_directory)) {
  952.             $this->DebugMessage('$this->config_cache_directory is not writable ('.$this->config_cache_directory.')'__FILE____LINE__);
  953.         }
  954.  
  955.         $this->InitializeTempDirSetting();
  956.         if (!@is_dir($this->config_temp_directory&& !@is_writable($this->config_temp_directory&& @is_dir($this->config_cache_directory&& @is_writable($this->config_cache_directory)) {
  957.             $this->DebugMessage('setting $this->config_temp_directory = $this->config_cache_directory ('.$this->config_cache_directory.')'__FILE____LINE__);
  958.             $this->config_temp_directory $this->config_cache_directory;
  959.         }
  960.         return true;
  961.     }
  962.  
  963.  
  964.     function ResolveFilenameToAbsolute($filename{
  965.         if (!$filename{
  966.             return false;
  967.         }
  968.  
  969.         //if (eregi('^(f|ht)tps?\://', $filename)) {
  970.         if (eregi('^[a-z0-9]+\:/{1,2}'$filename)) {
  971.             // eg: http://host/path/file.jpg (HTTP URL)
  972.             // eg: ftp://host/path/file.jpg  (FTP URL)
  973.             // eg: data1:/path/file.jpg      (Netware path)
  974.  
  975.             //$AbsoluteFilename = $filename;
  976.             return $filename;
  977.  
  978.         elseif ($this->iswindows && ($filename{1== ':')) {
  979.  
  980.             // absolute pathname (Windows)
  981.             $AbsoluteFilename $filename;
  982.  
  983.         elseif ($this->iswindows && ((substr($filename02== '//'|| (substr($filename02== '\\\\'))) {
  984.  
  985.             // absolute pathname (Windows)
  986.             $AbsoluteFilename $filename;
  987.  
  988.         elseif ($filename{0== '/'{
  989.  
  990.             if (@is_readable($filename&& !@is_readable($this->config_document_root.$filename)) {
  991.  
  992.                 // absolute filename (*nix)
  993.                 $AbsoluteFilename $filename;
  994.  
  995.             elseif ($filename{1== '~'{
  996.  
  997.                 // /~user/path
  998.                 if ($ApacheLookupURIarray phpthumb_functions::ApacheLookupURIarray($filename)) {
  999.                     $AbsoluteFilename $ApacheLookupURIarray['filename'];
  1000.                 else {
  1001.                     $AbsoluteFilename realpath($filename);
  1002.                     if (@is_readable($AbsoluteFilename)) {
  1003.                         $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'", but the correct filename ('.$AbsoluteFilename.') seems to have been resolved with realpath($filename)'__FILE____LINE__);
  1004.                     elseif (is_dir(dirname($AbsoluteFilename))) {
  1005.                         $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname($filename).'", but the correct directory ('.dirname($AbsoluteFilename).') seems to have been resolved with realpath(.)'__FILE____LINE__);
  1006.                     else {
  1007.                         return $this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'". This has been known to fail on Apache2 - try using the absolute filename for the source image (ex: "/home/user/httpdocs/image.jpg" instead of "/~user/image.jpg")');
  1008.                     }
  1009.                 }
  1010.  
  1011.             else {
  1012.  
  1013.                 // relative filename (any OS)
  1014.                 if (ereg('^'.preg_quote($this->config_document_root)$filename)) {
  1015.                     $AbsoluteFilename $filename;
  1016.                     $this->DebugMessage('ResolveFilenameToAbsolute() NOT prepending $this->config_document_root ('.$this->config_document_root.') to $filename ('.$filename.') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.'")'__FILE____LINE__);
  1017.                 else {
  1018.                     $AbsoluteFilename $this->config_document_root.$filename;
  1019.                     $this->DebugMessage('ResolveFilenameToAbsolute() prepending $this->config_document_root ('.$this->config_document_root.') to $filename ('.$filename.') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.'")'__FILE____LINE__);
  1020.                 }
  1021.  
  1022.             }
  1023.  
  1024.         else {
  1025.  
  1026.             // relative to current directory (any OS)
  1027.             $AbsoluteFilename $this->config_document_root.dirname(@$_SERVER['PHP_SELF']).DIRECTORY_SEPARATOR.$filename;
  1028.             //if (!@file_exists($AbsoluteFilename) && @file_exists(realpath($this->DotPadRelativeDirectoryPath($filename)))) {
  1029.             //    $AbsoluteFilename = realpath($this->DotPadRelativeDirectoryPath($filename));
  1030.             //}
  1031.  
  1032.             if (substr(dirname(@$_SERVER['PHP_SELF'])02== '/~'{
  1033.                 if ($ApacheLookupURIarray phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
  1034.                     $AbsoluteFilename $ApacheLookupURIarray['filename'].DIRECTORY_SEPARATOR.$filename;
  1035.                 else {
  1036.                     $AbsoluteFilename realpath('.').DIRECTORY_SEPARATOR.$filename;
  1037.                     if (@is_readable($AbsoluteFilename)) {
  1038.                         $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'", but the correct filename ('.$AbsoluteFilename.') seems to have been resolved with realpath(.)/$filename'__FILE____LINE__);
  1039.                     elseif (is_dir(dirname($AbsoluteFilename))) {
  1040.                         $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'", but the correct directory ('.dirname($AbsoluteFilename).') seems to have been resolved with realpath(.)'__FILE____LINE__);
  1041.                     else {
  1042.                         return $this->ErrorImage('phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname(@$_SERVER['PHP_SELF']).'". This has been known to fail on Apache2 - try using the absolute filename for the source image');
  1043.                     }
  1044.                 }
  1045.             }
  1046.  
  1047.         }
  1048.         if (is_link($AbsoluteFilename)) {
  1049.             $this->DebugMessage('is_link()==true, changing "'.$AbsoluteFilename.'" to "'.readlink($AbsoluteFilename).'"'__FILE____LINE__);
  1050.             $AbsoluteFilename readlink($AbsoluteFilename);
  1051.         }
  1052.         if (realpath($AbsoluteFilename)) {
  1053.             $AbsoluteFilename realpath($AbsoluteFilename);
  1054.         }
  1055.         if ($this->iswindows{
  1056.             $AbsoluteFilename eregi_replace('^'.preg_quote(realpath($this->config_document_root))realpath($this->config_document_root)$AbsoluteFilename);
  1057.             $AbsoluteFilename str_replace(DIRECTORY_SEPARATOR'/'$AbsoluteFilename);
  1058.         }
  1059.         if (!$this->config_allow_src_above_docroot && !ereg('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR'/'realpath($this->config_document_root)))$AbsoluteFilename)) {
  1060.             $this->DebugMessage('!$this->config_allow_src_above_docroot therefore setting "'.$AbsoluteFilename.'" (outside "'.realpath($this->config_document_root).'") to null'__FILE____LINE__);
  1061.             return false;
  1062.         }
  1063.         if (!$this->config_allow_src_above_phpthumb && !ereg('^'.preg_quote(str_replace(DIRECTORY_SEPARATOR'/'dirname(__FILE__)))$AbsoluteFilename)) {
  1064.             $this->DebugMessage('!$this->config_allow_src_above_phpthumb therefore setting "'.$AbsoluteFilename.'" (outside "'.dirname(__FILE__).'") to null'__FILE____LINE__);
  1065.             return false;
  1066.         }
  1067.         return $AbsoluteFilename;
  1068.     }
  1069.  
  1070.     function ImageMagickWhichConvert({
  1071.         static $WhichConvert null;
  1072.         if (is_null($WhichConvert)) {
  1073.             if ($this->iswindows{
  1074.                 $WhichConvert false;
  1075.             else {
  1076.                 $WhichConvert trim(phpthumb_functions::SafeExec('which convert'));
  1077.             }
  1078.         }
  1079.         return $WhichConvert;
  1080.     }
  1081.  
  1082.     function ImageMagickCommandlineBase({
  1083.         static $commandline null;
  1084.         if (is_null($commandline)) {
  1085.             $commandline (!is_null($this->config_imagemagick_path$this->config_imagemagick_path '');
  1086.  
  1087.             if ($this->config_imagemagick_path && ($this->config_imagemagick_path != realpath($this->config_imagemagick_path))) {
  1088.                 if (@is_executable(realpath($this->config_imagemagick_path))) {
  1089.                     $this->DebugMessage('Changing $this->config_imagemagick_path ('.$this->config_imagemagick_path.') to realpath($this->config_imagemagick_path) ('.realpath($this->config_imagemagick_path).')'__FILE____LINE__);
  1090.                     $this->config_imagemagick_path realpath($this->config_imagemagick_path);
  1091.                 else {
  1092.                     $this->DebugMessage('Leaving $this->config_imagemagick_path as ('.$this->config_imagemagick_path.') because !is_execuatable(realpath($this->config_imagemagick_path)) ('.realpath($this->config_imagemagick_path).')'__FILE____LINE__);
  1093.                 }
  1094.             }
  1095.             $this->DebugMessage('  file_exists('.$this->config_imagemagick_path.') = '.intval(  @file_exists($this->config_imagemagick_path))__FILE____LINE__);
  1096.             $this->DebugMessage('is_executable('.$this->config_imagemagick_path.') = '.intval(@is_executable($this->config_imagemagick_path))__FILE____LINE__);
  1097.             if (@file_exists($this->config_imagemagick_path)) {
  1098.                 $this->DebugMessage('using ImageMagick path from $this->config_imagemagick_path ('.$this->config_imagemagick_path.')'__FILE____LINE__);
  1099.                 if ($this->iswindows{
  1100.                     $commandline substr($this->config_imagemagick_path02).' && cd "'.str_replace('/'DIRECTORY_SEPARATORsubstr(dirname($this->config_imagemagick_path)2)).'" && '.basename($this->config_imagemagick_path);
  1101.                 else {
  1102.                     $commandline '"'.$this->config_imagemagick_path.'"';
  1103.                 }
  1104.                 return $commandline;
  1105.             }
  1106.  
  1107.             $which_convert $this->ImageMagickWhichConvert();
  1108.             $IMversion     $this->ImageMagickVersion();
  1109.  
  1110.             if ($which_convert && ($which_convert{0== '/'&& @file_exists($which_convert)) {
  1111.  
  1112.                 // `which convert` *should* return the path if "convert" exist, or nothing if it doesn't
  1113.                 // other things *may* get returned, like "sh: convert: not found" or "no convert in /usr/local/bin /usr/sbin /usr/bin /usr/ccs/bin"
  1114.                 // so only do this if the value returned exists as a file
  1115.                 $this->DebugMessage('using ImageMagick path from `which convert` ('.$which_convert.')'__FILE____LINE__);
  1116.                 $commandline 'convert';
  1117.  
  1118.             elseif ($IMversion{
  1119.  
  1120.                 $this->DebugMessage('setting ImageMagick path to $this->config_imagemagick_path ('.$this->config_imagemagick_path.') ['.$IMversion.']'__FILE____LINE__);
  1121.                 $commandline $this->config_imagemagick_path;
  1122.  
  1123.             else {
  1124.  
  1125.                 $this->DebugMessage('ImageMagickThumbnailToGD() aborting because cannot find convert in $this->config_imagemagick_path ('.$this->config_imagemagick_path.'), and `which convert` returned ('.$which_convert.')'__FILE____LINE__);
  1126.                 $commandline '';
  1127.  
  1128.             }
  1129.         }
  1130.         return $commandline;
  1131.     }
  1132.  
  1133.     function ImageMagickVersion($returnRAW=false{
  1134.         static $versionstring null;
  1135.         if (is_null($versionstring)) {
  1136.             $commandline $this->ImageMagickCommandlineBase();
  1137.             $commandline (!is_null($commandline$commandline '');
  1138.  
  1139.             $versionstring array(0=>''1=>'');
  1140.             if ($commandline{
  1141.                 $commandline .= ' --version';
  1142.                 $this->DebugMessage('ImageMagick version checked with "'.$commandline.'"'__FILE____LINE__);
  1143.                 $versionstring[1trim(phpthumb_functions::SafeExec($commandline));
  1144.                 if (eregi('^Version: [^0-9]*([ 0-9\\.\\:Q/]+) (http|file)\:'$versionstring[1]$matches)) {
  1145.                     $versionstring[0$matches[1];
  1146.                 else {
  1147.                     $versionstring[0false;
  1148.                     $this->DebugMessage('ImageMagick did not return recognized version string ('.$versionstring[1].')'__FILE____LINE__);
  1149.                 }
  1150.                 $this->DebugMessage('ImageMagick convert --version says "'.$matches[0].'"'__FILE____LINE__);
  1151.             }
  1152.         }
  1153.         return @$versionstring[intval($returnRAW)];
  1154.     }
  1155.  
  1156.     function ImageMagickSwitchAvailable($switchname{
  1157.         static $IMoptions null;
  1158.         if (is_null($IMoptions)) {
  1159.             $IMoptions array();
  1160.             $commandline $this->ImageMagickCommandlineBase();
  1161.             if (!is_null($commandline)) {
  1162.                 $commandline .= ' -help';
  1163.                 $IMhelp_lines explode("\n"phpthumb_functions::SafeExec($commandline));
  1164.                 foreach ($IMhelp_lines as $line{
  1165.                     if (ereg('^[\+\-]([a-z\-]+) 'trim($line)$matches)) {
  1166.                         $IMoptions[$matches[1]] true;
  1167.                     }
  1168.                 }
  1169.             }
  1170.         }
  1171.         if (is_array($switchname)) {
  1172.             $allOK true;
  1173.             foreach ($switchname as $key => $value{
  1174.                 if (!isset($IMoptions[$value])) {
  1175.                     $allOK false;
  1176.                     break;
  1177.                 }
  1178.             }
  1179.             $this->DebugMessage('ImageMagickSwitchAvailable('.implode(';'$switchname).') = '.intval($allOK).''__FILE____LINE__);
  1180.         else {
  1181.             $allOK = isset($IMoptions[$switchname]);
  1182.             $this->DebugMessage('ImageMagickSwitchAvailable('.$switchname.') = '.intval($allOK).''__FILE____LINE__);
  1183.         }
  1184.         return $allOK;
  1185.     }
  1186.  
  1187.     function ImageMagickFormatsList({
  1188.         static $IMformatsList null;
  1189.         if (is_null($IMformatsList)) {
  1190.             $IMformatsList '';
  1191.             $commandline $this->ImageMagickCommandlineBase();
  1192.             if (!is_null($commandline)) {
  1193.                 $commandline dirname($commandline).DIRECTORY_SEPARATOR.str_replace('convert''identify'basename($commandline));
  1194.                 $commandline .= ' -list format';
  1195.                 $IMformatsList phpthumb_functions::SafeExec($commandline);
  1196.             }
  1197.         }
  1198.         return $IMformatsList;
  1199.     }
  1200.  
  1201.     function ImageMagickThumbnailToGD({
  1202.         // http://www.imagemagick.org/script/command-line-options.php
  1203.  
  1204.         $this->useRawIMoutput true;
  1205.         if (phpthumb_functions::gd_version()) {
  1206.             // if GD is not available, must use whatever ImageMagick can output
  1207.  
  1208.             // $UnAllowedParameters contains options that can only be processed in GD, not ImageMagick
  1209.             // note: 'fltr' *may* need to be processed by GD, but we'll check that in more detail below
  1210.             $UnAllowedParameters array('xto''ra''ar''bg''bc');
  1211.             foreach ($UnAllowedParameters as $parameter{
  1212.                 if (isset($this->$parameter)) {
  1213.                     $this->DebugMessage('$this->useRawIMoutput=false because "'.$parameter.'" is set'__FILE____LINE__);
  1214.                     $this->useRawIMoutput false;
  1215.                     break;
  1216.                 }
  1217.             }
  1218.         }
  1219.         $this->DebugMessage('$this->useRawIMoutput='.($this->useRawIMoutput 'true' 'false').' after checking $UnAllowedParameters'__FILE____LINE__);
  1220.         $outputFormat $this->thumbnailFormat;
  1221.         if (phpthumb_functions::gd_version()) {
  1222.             if ($this->useRawIMoutput{
  1223.                 switch ($this->thumbnailFormat{
  1224.                     case 'gif':
  1225.                         $ImageCreateFunction 'ImageCreateFromGIF';
  1226.                         $this->is_alpha true;
  1227.                         break;
  1228.                     case 'png':
  1229.                         $ImageCreateFunction 'ImageCreateFromPNG';
  1230.                         $this->is_alpha true;
  1231.                         break;
  1232.                     case 'jpg':
  1233.                     case 'jpeg':
  1234.                         $ImageCreateFunction 'ImageCreateFromJPEG';
  1235.                         break;
  1236.                     default:
  1237.                         $this->DebugMessage('Forcing output to PNG because $this->thumbnailFormat ('.$this->thumbnailFormat.' is not a GD-supported format)'__FILE____LINE__);
  1238.                         $outputFormat 'png';
  1239.                         $ImageCreateFunction 'ImageCreateFromPNG';
  1240.                         $this->is_alpha true;
  1241.                         $this->useRawIMoutput false;
  1242.                         break;
  1243.                 }
  1244.                 if (!function_exists(@$ImageCreateFunction)) {
  1245.                     // ImageMagickThumbnailToGD() depends on ImageCreateFromPNG/ImageCreateFromGIF
  1246.                     //$this->DebugMessage('ImageMagickThumbnailToGD() aborting because '.@$ImageCreateFunction.'() is not available', __FILE__, __LINE__);
  1247.                     $this->useRawIMoutput true;
  1248.                     //return false;
  1249.                 }
  1250.             else {
  1251.                 $outputFormat 'png';
  1252.                 $ImageCreateFunction 'ImageCreateFromPNG';
  1253.                 $this->is_alpha true;
  1254.                 $this->useRawIMoutput false;
  1255.             }
  1256.         }
  1257.  
  1258.         if (!$this->sourceFilename && $this->rawImageData{
  1259.             if ($IMtempSourceFilename $this->phpThumb_tempnam()) {
  1260.                 $IMtempSourceFilename realpath($IMtempSourceFilename);
  1261.                 $this->sourceFilename $IMtempSourceFilename;
  1262.                 $this->DebugMessage('ImageMagickThumbnailToGD() setting $this->sourceFilename to "'.$IMtempSourceFilename.'" from $this->rawImageData ('.strlen($this->rawImageData).' bytes)'__FILE____LINE__);
  1263.             }
  1264.         }
  1265.         if (!$this->sourceFilename{
  1266.             $this->DebugMessage('ImageMagickThumbnailToGD() aborting because $this->sourceFilename is empty'__FILE____LINE__);
  1267.             $this->useRawIMoutput false;
  1268.             return false;
  1269.         }
  1270.         if (ini_get('safe_mode')) {
  1271.             $this->DebugMessage('ImageMagickThumbnailToGD() aborting because safe_mode is enabled'__FILE____LINE__);
  1272.             $this->useRawIMoutput false;
  1273.             return false;
  1274.         }
  1275.  
  1276.         $commandline $this->ImageMagickCommandlineBase();
  1277.         if ($commandline{
  1278.             if ($IMtempfilename $this->phpThumb_tempnam()) {
  1279.                 $IMtempfilename realpath($IMtempfilename);
  1280.  
  1281.                 $IMuseExplicitImageOutputDimensions false;
  1282.                 if ($this->ImageMagickSwitchAvailable('thumbnail'&& $this->config_imagemagick_use_thumbnail{
  1283.                     $IMresizeParameter 'thumbnail';
  1284.                 else {
  1285.                     $IMresizeParameter 'resize';
  1286.  
  1287.                     // some (older? around 2002) versions of IM won't accept "-resize 100x" but require "-resize 100x100"
  1288.                     $commandline_test $this->ImageMagickCommandlineBase().' logo: -resize 1x "'.$IMtempfilename.'" 2>&1';
  1289.                     $IMresult_test phpthumb_functions::SafeExec($commandline_test);
  1290.                     $IMuseExplicitImageOutputDimensions eregi('image dimensions are zero'$IMresult_test);
  1291.                     $this->DebugMessage('IMuseExplicitImageOutputDimensions = '.intval($IMuseExplicitImageOutputDimensions)__FILE____LINE__);
  1292.                     if ($fp_im_temp @fopen($IMtempfilename'wb')) {
  1293.                         // erase temp image so ImageMagick logo doesn't get output if other processing fails
  1294.                         fclose($fp_im_temp);
  1295.                     }
  1296.                 }
  1297.  
  1298.  
  1299.                 if (!is_null($this->dpi&& $this->ImageMagickSwitchAvailable('density')) {
  1300.                     // for raster source formats only (WMF, PDF, etc)
  1301.                     $commandline .= ' -density '.$this->dpi;
  1302.                 }
  1303.                 ob_start();
  1304.                 $getimagesize GetImageSize($this->sourceFilename);
  1305.                 $GetImageSizeError ob_get_contents();
  1306.                 ob_end_clean();
  1307.                 if (is_array($getimagesize)) {
  1308.                     $this->DebugMessage('GetImageSize('.$this->sourceFilename.') SUCCEEDED: '.serialize($getimagesize)__FILE____LINE__);
  1309.                 else {
  1310.                     $this->DebugMessage('GetImageSize('.$this->sourceFilename.') FAILED with error "'.$GetImageSizeError.'"'__FILE____LINE__);
  1311.                 }
  1312.                 if (is_array($getimagesize)) {
  1313.                     $this->DebugMessage('GetImageSize('.$this->sourceFilename.') returned [w='.$getimagesize[0].';h='.$getimagesize[1].';f='.$getimagesize[2].']'__FILE____LINE__);
  1314.                     $this->source_width  $getimagesize[0];
  1315.                     $this->source_height $getimagesize[1];
  1316.                     $this->DebugMessage('source dimensions set to '.$this->source_width.'x'.$this->source_height__FILE____LINE__);
  1317.                     $this->SetOrientationDependantWidthHeight();
  1318.  
  1319.                     if (!eregi('('.implode('|'$this->AlphaCapableFormats).')'$outputFormat)) {
  1320.                         // not a transparency-capable format
  1321.                         $commandline .= ' -background "#'.($this->bg $this->bg 'FFFFFF').'"';
  1322.                         if ($getimagesize[2== 1{
  1323.                             $commandline .= ' -flatten';
  1324.                         }
  1325.                     }
  1326.                     if ($getimagesize[2== 1{
  1327.                         $commandline .= ' -coalesce'// may be needed for animated GIFs
  1328.                     }
  1329.                     if ($this->source_width || $this->source_height{
  1330.                         if ($this->zc{
  1331.  
  1332.                             $borderThickness 0;
  1333.                             if (!empty($this->fltr)) {
  1334.                                 foreach ($this->fltr as $key => $value{
  1335.                                     if (ereg('^bord\|([0-9]+)'$value$matches)) {
  1336.                                         $borderThickness $matches[1];
  1337.                                         break;
  1338.                                     }
  1339.                                 }
  1340.                             }
  1341.                             $wAll intval(max($this->w$this->wp$this->wl$this->ws)) ($borderThickness);
  1342.                             $hAll intval(max($this->h$this->hp$this->hl$this->hs)) ($borderThickness);
  1343.                             $imAR $this->source_width $this->source_height;
  1344.                             $zcAR (($wAll && $hAll$wAll $hAll 1);
  1345.                             $side  phpthumb_functions::nonempty_min($this->source_width$this->source_heightmax($wAll$hAll));
  1346.                             $sideX phpthumb_functions::nonempty_min($this->source_width,                       $wAllround($hAll $zcAR));
  1347.                             $sideY phpthumb_functions::nonempty_min(                     $this->source_height$hAllround($wAll $zcAR));
  1348.  
  1349.                             $thumbnailH round(max($sideY($sideY $zcAR$imAR));
  1350.                             if ($IMuseExplicitImageOutputDimensions{
  1351.                                 $commandline .= ' -'.$IMresizeParameter.' '.$thumbnailH.'x'.$thumbnailH;
  1352.                             else {
  1353.                                 $commandline .= ' -'.$IMresizeParameter.' x'.$thumbnailH;
  1354.                             }
  1355.  
  1356.                             switch (strtoupper($this->zc)) {
  1357.                                 case 'T':
  1358.                                     $commandline .= ' -gravity north';
  1359.                                     break;
  1360.                                 case 'B':
  1361.                                     $commandline .= ' -gravity south';
  1362.                                     break;
  1363.                                 case 'L':
  1364.                                     $commandline .= ' -gravity west';
  1365.                                     break;
  1366.                                 case 'R':
  1367.                                     $commandline .= ' -gravity east';
  1368.                                     break;
  1369.                                 case 'TL':
  1370.                                     $commandline .= ' -gravity northwest';
  1371.                                     break;
  1372.                                 case 'TR':
  1373.                                     $commandline .= ' -gravity northeast';
  1374.                                     break;
  1375.                                 case 'BL':
  1376.                                     $commandline .= ' -gravity southwest';
  1377.                                     break;
  1378.                                 case 'BR':
  1379.                                     $commandline .= ' -gravity southeast';
  1380.                                     break;
  1381.                                 case '1':
  1382.                                 case 'C':
  1383.                                 default:
  1384.                                     $commandline .= ' -gravity center';
  1385.                                     break;
  1386.                             }
  1387.  
  1388.                             if (($wAll 0&& ($hAll 0)) {
  1389.                                 $commandline .= ' -crop '.$wAll.'x'.$hAll.'+0+0';
  1390.                             else {
  1391.                                 $commandline .= ' -crop '.$side.'x'.$side.'+0+0';
  1392.                             }
  1393.                             if ($this->ImageMagickSwitchAvailable('repage')) {
  1394.                                 $commandline .= ' +repage';
  1395.                             else {
  1396.                                 $this->DebugMessage('Skipping "+repage" because ImageMagick (v'.$this->ImageMagickVersion().') does not support it'__FILE____LINE__);
  1397.                             }
  1398.  
  1399.                         elseif ($this->sw || $this->sh || $this->sx || $this->sy{
  1400.  
  1401.                             $commandline .= ' -crop '.($this->sw $this->sw $this->source_width).'x'.($this->sh $this->sh $this->source_height).'+'.$this->sx.'+'.$this->sy;
  1402.                             // this is broken for aoe=1, but unsure how to fix. Send advice to info@silisoftware.com
  1403.                             if ($this->w || $this->h{
  1404.                                 if ($this->ImageMagickSwitchAvailable('repage')) {
  1405.                                     $commandline .= ' -repage';
  1406.                                 else {
  1407.                                     $this->DebugMessage('Skipping "-repage" because ImageMagick (v'.$this->ImageMagickVersion().') does not support it'__FILE____LINE__);
  1408.                                 }
  1409.                                 if ($IMuseExplicitImageOutputDimensions{
  1410.                                     if ($this->w && !$this->h{
  1411.                                         $this->h ceil($this->w ($this->source_width $this->source_height));
  1412.                                     elseif ($this->h && !$this->w{
  1413.                                         $this->w ceil($this->h ($this->source_width $this->source_height));
  1414.                                     }
  1415.                                 }
  1416.                                 $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
  1417.                             }
  1418.  
  1419.                         else {
  1420.  
  1421.                             if ($this->iar && (intval($this->w0&& (intval($this->h0)) {
  1422.                                 $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h.'!';
  1423.                             else {
  1424.                                 $this->w ((($this->aoe || $this->far&& $this->w$this->w ($this->w phpthumb_functions::nonempty_min($this->w$getimagesize[0]''));
  1425.                                 $this->h ((($this->aoe || $this->far&& $this->h$this->h ($this->h phpthumb_functions::nonempty_min($this->h$getimagesize[1]''));
  1426.                                 if ($this->w || $this->h{
  1427.                                     if ($IMuseExplicitImageOutputDimensions{
  1428.                                         if ($this->w && !$this->h{
  1429.                                             $this->h ceil($this->w ($this->source_width $this->source_height));
  1430.                                         elseif ($this->h && !$this->w{
  1431.                                             $this->w ceil($this->h ($this->source_width $this->source_height));
  1432.                                         }
  1433.                                     }
  1434.                                     $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
  1435.                                 }
  1436.                             }
  1437.                         }
  1438.                     }
  1439.  
  1440.                 else {
  1441.  
  1442.                     $this->DebugMessage('GetImageSize('.$this->sourceFilename.') failed'__FILE____LINE__);
  1443.                     if ($this->w || $this->h{
  1444.                         if ($IMuseExplicitImageOutputDimensions{
  1445.                             // unknown source aspect ration, just put large number and hope IM figures it out
  1446.                             $commandline .= ' -'.$IMresizeParameter.' '.($this->w $this->w '9999').'x'.($this->h $this->h '9999');
  1447.                         else {
  1448.                             $commandline .= ' -'.$IMresizeParameter.' '.$this->w.'x'.$this->h;
  1449.                         }
  1450.                         if ($this->iar && (intval($this->w0&& (intval($this->h0)) {
  1451.                             $commandline .= '!';
  1452.                         }
  1453.                     }
  1454.  
  1455.                 }
  1456.                 foreach ($this->fltr as $filterkey => $filtercommand{
  1457.                     @list($command$parameterexplode('|'$filtercommand2);
  1458.                     switch ($command{
  1459.                         case 'brit':
  1460.                             if ($this->ImageMagickSwitchAvailable('modulate')) {
  1461.                                 $commandline .= ' -modulate '.(100 $parameter).',100,100';
  1462.                                 unset($this->fltr[$filterkey]);
  1463.                             }
  1464.                             break;
  1465.  
  1466.                         case 'cont':
  1467.                             if ($this->ImageMagickSwitchAvailable('contrast')) {
  1468.                                 $contDiv10 round($parameter 10);
  1469.                                 if ($contDiv10 0{
  1470.                                     for ($i 0$i $contDiv10$i++{
  1471.                                         $commandline .= ' -contrast'// increase contrast by 10%
  1472.                                     }
  1473.                                 elseif ($contDiv10 0{
  1474.                                     for ($i $contDiv10$i 0$i++{
  1475.                                         $commandline .= ' +contrast'// decrease contrast by 10%
  1476.                                     }
  1477.                                 else {
  1478.                                     // do nothing
  1479.                                 }
  1480.                                 unset($this->fltr[$filterkey]);
  1481.                             }
  1482.                             break;
  1483.  
  1484.                         case 'ds':
  1485.                             if ($this->ImageMagickSwitchAvailable(array('colorspace''modulate'))) {
  1486.                                 if ($parameter == 100{
  1487.                                     $commandline .= ' -colorspace GRAY -modulate 100,0,100';
  1488.                                 else {
  1489.                                     $commandline .= ' -modulate 100,'.(100 $parameter).',100';
  1490.                                 }
  1491.                                 unset($this->fltr[$filterkey]);
  1492.                             }
  1493.                             break;
  1494.  
  1495.                         case 'sat':
  1496.                             if ($this->ImageMagickSwitchAvailable(array('colorspace''modulate'))) {
  1497.                                 if ($parameter == -100{
  1498.                                     $commandline .= ' -colorspace GRAY -modulate 100,0,100';
  1499.                                 else {
  1500.                                     $commandline .= ' -modulate 100,'.(100 $parameter).',100';
  1501.                                 }
  1502.                                 unset($this->fltr[$filterkey]);
  1503.                             }
  1504.                             break;
  1505.  
  1506.                         case 'gray':
  1507.                             if ($this->ImageMagickSwitchAvailable(array('colorspace''modulate'))) {
  1508.                                 $commandline .= ' -colorspace GRAY -modulate 100,0,100';
  1509.                                 //$commandline .= ' -colorspace GRAY';
  1510.                                 unset($this->fltr[$filterkey]);
  1511.                             }
  1512.                             break;
  1513.  
  1514.                         case 'clr':
  1515.                             if ($this->ImageMagickSwitchAvailable(array('fill''colorize'))) {
  1516.                                 @list($amount$colorexplode('|'$parameter);
  1517.                                 $commandline .= ' -fill "#'.$color.'" -colorize '.$amount;
  1518.                             }
  1519.                             break;
  1520.  
  1521.                         case 'sep':
  1522.                             if ($this->ImageMagickSwitchAvailable('sepia-tone')) {
  1523.                                 @list($amount$colorexplode('|'$parameter);
  1524.                                 $amount ($amount $amount 80);
  1525.                                 if (!$color{
  1526.                                     $commandline .= ' -sepia-tone '.$amount.'%';
  1527.                                     unset($this->fltr[$filterkey]);
  1528.                                 }
  1529.                             }
  1530.                             break;
  1531.  
  1532.                         case 'gam':
  1533.                             if ($this->ImageMagickSwitchAvailable('gamma')) {
  1534.                                 $commandline .= ' -gamma '.$parameter;
  1535.                                 unset($this->fltr[$filterkey]);
  1536.                             }
  1537.                             break;
  1538.  
  1539.                         case 'neg':
  1540.                             if ($this->ImageMagickSwitchAvailable('negate')) {
  1541.                                 $commandline .= ' -negate';
  1542.                                 unset($this->fltr[$filterkey]);
  1543.                             }
  1544.                             break;
  1545.  
  1546.                         case 'th':
  1547.                             if ($this->ImageMagickSwitchAvailable(array('threshold''dither''monochrome'))) {
  1548.                                 $commandline .= ' -threshold '.round($parameter 2.55).'% -dither -monochrome';
  1549.                                 unset($this->fltr[$filterkey]);
  1550.                             }
  1551.                             break;
  1552.  
  1553.                         case 'rcd':
  1554.                             if ($this->ImageMagickSwitchAvailable(array('colors''dither'))) {
  1555.                                 @list($colors$ditherexplode('|'$parameter);
  1556.                                 $colors ($colors                ?  (int) $colors 256);
  1557.                                 $dither  ((strlen($dither0? (bool) $dither true);
  1558.                                 $commandline .= ' -colors '.max($colors8)// ImageMagick will otherwise fail with "cannot quantize to fewer than 8 colors"
  1559.                                 $commandline .= ($dither ' -dither' ' +dither');
  1560.                                 unset($this->fltr[$filterkey]);
  1561.                             }
  1562.                             break;
  1563.  
  1564.                         case 'flip':
  1565.                             if ($this->ImageMagickSwitchAvailable(array('flip''flop'))) {
  1566.                                 if (strpos(strtolower($parameter)'x'!== false{
  1567.                                     $commandline .= ' -flop';
  1568.                                 }
  1569.                                 if (strpos(strtolower($parameter)'y'!== false{
  1570.                                     $commandline .= ' -flip';
  1571.                                 }
  1572.                                 unset($this->fltr[$filterkey]);
  1573.                             }
  1574.                             break;
  1575.  
  1576.                         case 'edge':
  1577.                             if ($this->ImageMagickSwitchAvailable('edge')) {
  1578.                                 $parameter ($parameter $parameter 2);
  1579.                                 $commandline .= ' -edge '.($parameter $parameter 1);
  1580.                                 unset($this->fltr[$filterkey]);
  1581.                             }
  1582.                             break;
  1583.  
  1584.                         case 'emb':
  1585.                             if ($this->ImageMagickSwitchAvailable(array('emboss''negate'))) {
  1586.                                 $parameter ($parameter $parameter 2);
  1587.                                 $commandline .= ' -emboss '.$parameter;
  1588.                                 if ($parameter 2{
  1589.                                     $commandline .= ' -negate'// ImageMagick negates the image for some reason with '-emboss 1';
  1590.                                 }
  1591.                                 unset($this->fltr[$filterkey]);
  1592.                             }
  1593.                             break;
  1594.  
  1595.                         case 'lvl':
  1596.                             @list($band$method$thresholdexplode('|'$parameter);
  1597.                             $band      ($band ereg_replace('[^RGBA\\*]'''strtoupper($band)) '*');
  1598.                             $method    ((strlen($method0)    intval($method)                :   2);
  1599.                             $threshold ((strlen($threshold0floatval($threshold)           0.1);
  1600.  
  1601.                             $band ereg_replace('[^RGBA\\*]'''strtoupper($band));
  1602.  
  1603.                             if (($method 1&& !$this->ImageMagickSwitchAvailable(array('channel''contrast-stretch'))) {
  1604.                                 // Because ImageMagick processing happens before PHP-GD filters, and because some
  1605.                                 // clipping is involved in the "lvl" filter, if "lvl" happens before "wb" then the
  1606.                                 // "wb" filter will have (almost) no effect. Therefore, if "wb" is enabled then
  1607.                                 // force the "lvl" filter to be processed by GD, not ImageMagick.
  1608.                                 foreach ($this->fltr as $fltr_key => $fltr_value{
  1609.                                     list($fltr_cmdexplode('|'$fltr_value);
  1610.                                     if ($fltr_cmd == 'wb'{
  1611.                                         $this->DebugMessage('Setting "lvl" filter method to "0" (from "'.$method.'") because white-balance filter also enabled'__FILE____LINE__);
  1612.                                         $method 0;
  1613.                                     }
  1614.                                 }
  1615.                             }
  1616.  
  1617.                             switch ($method{
  1618.                                 case 0// internal RGB
  1619.                                 case 1// internal grayscale
  1620.                                     break;
  1621.                                 case 2// ImageMagick "contrast-stretch"
  1622.                                     if ($this->ImageMagickSwitchAvailable('contrast-stretch')) {
  1623.                                         $thiscommand ' -contrast-stretch '.$threshold.'%';
  1624.                                         $commandline .= (($band == '*'$thiscommand ' -channel '.strtoupper($band).$thiscommand.' +channel');
  1625.                                         unset($this->fltr[$filterkey]);
  1626.                                     }
  1627.                                     break;
  1628.                                 case 3// ImageMagick "normalize"
  1629.                                     if ($this->ImageMagickSwitchAvailable('normalize')) {
  1630.                                         $thiscommand ' -normalize';
  1631.                                         $commandline .= (($band == '*'$thiscommand ' -channel '.strtoupper($band).$thiscommand.' +channel');
  1632.                                         unset($this->fltr[$filterkey]);
  1633.                                     }
  1634.                                     break;
  1635.                                 default:
  1636.                                     $this->DebugMessage('unsupported method ('.$method.') for "lvl" filter'__FILE____LINE__);
  1637.                                     break;
  1638.                             }
  1639.                             if (isset($this->fltr[$filterkey]&& ($method 1)) {
  1640.                                 $this->fltr[$filterkey$command.'|'.$band.'|0|'.$threshold;
  1641.                                 $this->DebugMessage('filter "lvl" remapped from method "'.$method.'" to method "0" because ImageMagick support is missing'__FILE____LINE__);
  1642.                             }
  1643.                             break;
  1644.  
  1645.                         case 'wb':
  1646.                             if ($this->ImageMagickSwitchAvailable(array('channel''contrast-stretch'))) {
  1647.                                 @list($thresholdexplode('|'$parameter);
  1648.                                 $threshold (is_float($threshold$threshold 0.1);
  1649.                                 $commandline .= ' -channel R -contrast-stretch '.$threshold.'%';
  1650.                                 $commandline .= ' -channel G -contrast-stretch '.$threshold.'%';
  1651.                                 $commandline .= ' -channel B -contrast-stretch '.$threshold.'%';
  1652.                                 $commandline .= ' +channel';
  1653.                                 unset($this->fltr[$filterkey]);
  1654.                             }
  1655.                             break;
  1656.  
  1657.                         case 'blur':
  1658.                             if ($this->ImageMagickSwitchAvailable('blur')) {
  1659.                                 @list($radiusexplode('|'$parameter);
  1660.                                 $radius ($radius $radius 1);
  1661.                                 $commandline .= ' -blur '.$radius;
  1662.                                 unset($this->fltr[$filterkey]);
  1663.                             }
  1664.                             break;
  1665.  
  1666.                         case 'gblr':
  1667.                             if ($this->ImageMagickSwitchAvailable('gaussian')) {
  1668.                                 @list($radiusexplode('|'$parameter);
  1669.                                 $radius ($radius $radius 1);
  1670.                                 $commandline .= ' -gaussian '.$radius;
  1671.                                 unset($this->fltr[$filterkey]);
  1672.                             }
  1673.                             break;
  1674.  
  1675.                         case 'usm':
  1676.                             if ($this->ImageMagickSwitchAvailable('unsharp')) {
  1677.                                 @list($amount$radius$thresholdexplode('|'$parameter);
  1678.                                 $amount    ($amount            $amount    80);
  1679.                                 $radius    ($radius            $radius    0.5);
  1680.                                 $threshold (strlen($threshold$threshold 3);
  1681.                                 $commandline .= ' -unsharp '.number_format(($radius 212).'x1+'.number_format($amount 1002).'+'.number_format($threshold 1002);
  1682.                                 unset($this->fltr[$filterkey]);
  1683.                             }
  1684.                             break;
  1685.  
  1686.                         case 'bord':
  1687.                             if ($this->ImageMagickSwitchAvailable(array('border''bordercolor''thumbnail''crop'))) {
  1688.                                 if (!$this->zc{
  1689.                                     @list($width$rX$rY$colorexplode('|'$parameter);
  1690.                                     if ($width && !$rX && !$rY{
  1691.                                         if (!phpthumb_functions::IsHexColor($color)) {
  1692.                                             $color ($this->bc $this->bc '000000');
  1693.                                         }
  1694.                                         $commandline .= ' -border '.$width.' -bordercolor "#'.$color.'"';
  1695.                                         if (ereg(' \-crop ([0-9]+)x([0-9]+)\+0\+0 '$commandline$matches)) {
  1696.                                             $commandline str_replace(' -crop '.$matches[1].'x'.$matches[2].'+0+0 '' -crop '.($matches[1($width)).'x'.($matches[2($width)).'+0+0 '$commandline);
  1697.                                         elseif (ereg(' \-'.$IMresizeParameter.' ([0-9]+)x([0-9]+) '$commandline$matches)) {
  1698.                                             $commandline str_replace(' -'.$IMresizeParameter.' '.$matches[1].'x'.$matches[2].' '' -'.$IMresizeParameter.' '.($matches[1($width)).'x'.($matches[2($width)).' '$commandline);
  1699.                                         }
  1700.                                         unset($this->fltr[$filterkey]);
  1701.                                     }
  1702.                                 }
  1703.                             }
  1704.                             break;
  1705.  
  1706.                         case 'crop':
  1707.                             break;
  1708.  
  1709.                         case 'sblr':
  1710.                             break;
  1711.  
  1712.                         case 'mean':
  1713.                             break;
  1714.  
  1715.                         case 'smth':
  1716.                             break;
  1717.  
  1718.                         case 'bvl':
  1719.                             break;
  1720.  
  1721.                         case 'wmi':
  1722.                             break;
  1723.  
  1724.                         case 'wmt':
  1725.                             break;
  1726.  
  1727.                         case 'over':
  1728.                             break;
  1729.  
  1730.                         case 'hist':
  1731.                             break;
  1732.  
  1733.                         case 'fram':
  1734.                             break;
  1735.  
  1736.                         case 'drop':
  1737.                             break;
  1738.  
  1739.                         case 'mask':
  1740.                             break;
  1741.  
  1742.                         case 'elip':
  1743.                             break;
  1744.  
  1745.                         case 'ric':
  1746.                             break;
  1747.  
  1748.                         case 'stc':
  1749.                             break;
  1750.  
  1751.                         case 'size':
  1752.                             break;
  1753.  
  1754.                         default:
  1755.                             $this->DebugMessage('Unknown $this->fltr['.$filterkey.'] ('.$filtercommand.') -- deleting filter command'__FILE____LINE__);
  1756.                             unset($this->fltr[$filterkey]);
  1757.                             break;
  1758.                     }
  1759.                     if (!isset($this->fltr[$filterkey])) {
  1760.                         $this->DebugMessage('Processed $this->fltr['.$filterkey.'] ('.$filtercommand.') with ImageMagick'__FILE____LINE__);
  1761.                     else {
  1762.                         $this->DebugMessage('Skipping $this->fltr['.$filterkey.'] ('.$filtercommand.') with ImageMagick'__FILE____LINE__);
  1763.                     }
  1764.                 }
  1765.                 $this->DebugMessage('Remaining $this->fltr after ImageMagick: ('.$this->phpThumbDebugVarDump($this->fltr).')'__FILE____LINE__);
  1766.                 if (count($this->fltr0{
  1767.                     $this->useRawIMoutput false;
  1768.                 }
  1769.  
  1770.                 if (eregi('jpe?g'$outputFormat&& $this->q{
  1771.                     if ($this->ImageMagickSwitchAvailable(array('quality''interlace'))) {
  1772.                         $commandline .= ' -quality '.$this->thumbnailQuality;
  1773.                         if ($this->config_output_interlace{
  1774.                             // causes weird things with animated GIF... leave for JPEG only
  1775.                             $commandline .= ' -interlace line '// Use Line or Plane to create an interlaced PNG or GIF or progressive JPEG image
  1776.                         }
  1777.                     }
  1778.                 }
  1779.                 $commandline .= ' "'.str_replace('/'DIRECTORY_SEPARATOR$this->sourceFilename).(($outputFormat == 'gif''' '['.intval($this->sfn).']').'"'// [0] means first frame of (GIF) animation, can be ignored
  1780.                 $commandline .= ' '.$outputFormat.':"'.$IMtempfilename.'"';
  1781.                 if (!$this->iswindows{
  1782.                     $commandline .= ' 2>&1';
  1783.                 }
  1784.                 $this->DebugMessage('ImageMagick called as ('.$commandline.')'__FILE____LINE__);
  1785.                 $IMresult phpthumb_functions::SafeExec($commandline);
  1786.                 clearstatcache();
  1787.                 if (@$IMtempSourceFilename && file_exists($IMtempSourceFilename)) {
  1788.                     @unlink($IMtempSourceFilename);
  1789.                 }
  1790.                 if (!@file_exists($IMtempfilename|| !@filesize($IMtempfilename)) {
  1791.                     $this->FatalError('ImageMagick failed with message ('.trim($IMresult).')');
  1792.                     $this->DebugMessage('ImageMagick failed with message ('.trim($IMresult).')'__FILE____LINE__);
  1793.                     if ($this->iswindows && !$IMresult{
  1794.                         $this->DebugMessage('Check to make sure that PHP has read+write permissions to "'.dirname($IMtempfilename).'"'__FILE____LINE__);
  1795.                     }
  1796.  
  1797.                 else {
  1798.  
  1799.                     $this->IMresizedData file_get_contents($IMtempfilename);
  1800.                     $getimagesize_imresized @GetImageSize($IMtempfilename);
  1801.                     $this->DebugMessage('GetImageSize('.$IMtempfilename.') returned [w='.$getimagesize_imresized[0].';h='.$getimagesize_imresized[1].';f='.$getimagesize_imresized[2].']'__FILE____LINE__);
  1802.                     if (($this->config_max_source_pixels 0&& (($getimagesize_imresized[0$getimagesize_imresized[1]$this->config_max_source_pixels)) {
  1803.                         $this->DebugMessage('skipping ImageMagickThumbnailToGD::'.$ImageCreateFunction.'() because IM output is too large ('.$getimagesize_imresized[0].'x'.$getimagesize_imresized[0].' = '.($getimagesize_imresized[0$getimagesize_imresized[1]).' > '.$this->config_max_source_pixels.')'__FILE____LINE__);
  1804.                     elseif (function_exists(@$ImageCreateFunction&& ($this->gdimg_source @$ImageCreateFunction($IMtempfilename))) {
  1805.                         $this->source_width  ImageSX($this->gdimg_source);
  1806.                         $this->source_height ImageSY($this->gdimg_source);
  1807.                         $this->DebugMessage('ImageMagickThumbnailToGD::'.$ImageCreateFunction.'() succeeded, $this->gdimg_source is now ('.$this->source_width.'x'.$this->source_height.')'__FILE____LINE__);
  1808.                         $this->DebugMessage('ImageMagickThumbnailToGD() returning $IMresizedData ('.strlen($this->IMresizedData).' bytes)'__FILE____LINE__);
  1809.                     else {
  1810.                         $this->useRawIMoutput true;
  1811.                         $this->DebugMessage('$this->useRawIMoutput set to TRUE because '.@$ImageCreateFunction.'('.$IMtempfilename.') failed'__FILE____LINE__);
  1812.                     }
  1813.                     @unlink($IMtempfilename);
  1814.                     return true;
  1815.  
  1816.                 }
  1817.                 unlink($IMtempfilename);
  1818.  
  1819.             else {
  1820.                 $this->DebugMessage('ImageMagickThumbnailToGD() aborting, phpThumb_tempnam() failed'__FILE____LINE__);
  1821.             }
  1822.         else {
  1823.             $this->DebugMessage('ImageMagickThumbnailToGD() aborting because ImageMagickCommandlineBase() failed'__FILE____LINE__);
  1824.         }
  1825.         $this->useRawIMoutput false;
  1826.         return false;
  1827.     }
  1828.  
  1829.  
  1830.     function Rotate({
  1831.         if ($this->ra || $this->ar{
  1832.             if (!function_exists('ImageRotate')) {
  1833.                 $this->DebugMessage('!function_exists(ImageRotate)'__FILE____LINE__);
  1834.                 return false;
  1835.             }
  1836.             if (!include_once(dirname(__FILE__).'/phpthumb.filters.php')) {
  1837.                 $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';'$this->fltr).')'__FILE____LINE__);
  1838.                 return false;
  1839.             }
  1840.  
  1841.             $this->config_background_hexcolor ($this->bg $this->bg $this->config_background_hexcolor);
  1842.             if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
  1843.                 return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
  1844.             }
  1845.  
  1846.             $rotate_angle 0;
  1847.             if ($this->ra{
  1848.  
  1849.                 $rotate_angle floatval($this->ra);
  1850.  
  1851.             else {
  1852.  
  1853.                 if ($this->ar == 'x'{
  1854.                     if (phpthumb_functions::version_compare_replacement(phpversion()'4.2.0''>=')) {
  1855.                         if ($this->sourceFilename{
  1856.                             if (function_exists('exif_read_data')) {
  1857.                                 if ($exif_data @exif_read_data($this->sourceFilename'IFD0')) {
  1858.                                     // http://sylvana.net/jpegcrop/exif_orientation.html
  1859.                                     switch (@$exif_data['Orientation']{
  1860.                                         case 1:
  1861.                                             $rotate_angle 0;
  1862.                                             break;
  1863.                                         case 3:
  1864.                                             $rotate_angle 180;
  1865.                                             break;
  1866.                                         case 6:
  1867.                                             $rotate_angle 270;
  1868.                                             break;
  1869.                                         case 8:
  1870.                                             $rotate_angle 90;
  1871.                                             break;
  1872.  
  1873.                                         default:
  1874.                                             $this->DebugMessage('EXIF auto-rotate failed because unknown $exif_data[Orientation] "'.@$exif_data['Orientation'].'"'__FILE____LINE__);
  1875.                                             return false;
  1876.                                             break;
  1877.                                     }
  1878.                                     $this->DebugMessage('EXIF auto-rotate set to '.$rotate_angle.' degrees ($exif_data[Orientation] = "'.@$exif_data['Orientation'].'")'__FILE____LINE__);
  1879.                                 else {
  1880.                                     $this->DebugMessage('failed: exif_read_data('.$this->sourceFilename.')'__FILE____LINE__);
  1881.                                     return false;
  1882.                                 }
  1883.                             else {
  1884.                                 $this->DebugMessage('!function_exists(exif_read_data)'__FILE____LINE__);
  1885.                                 return false;
  1886.                             }
  1887.                         else {
  1888.                             $this->DebugMessage('Cannot auto-rotate from EXIF data because $this->sourceFilename is empty'__FILE____LINE__);
  1889.                             return false;
  1890.                         }
  1891.                     else {
  1892.                         $this->DebugMessage('Cannot auto-rotate from EXIF data because PHP is less than v4.2.0 ('.phpversion().')'__FILE____LINE__);
  1893.                         return false;
  1894.                     }
  1895.                 elseif (($this->ar == 'l'&& ($this->source_height $this->source_width)) {
  1896.                     $rotate_angle 270;
  1897.                 elseif (($this->ar == 'L'&& ($this->source_height $this->source_width)) {
  1898.                     $rotate_angle 90;
  1899.                 elseif (($this->ar == 'p'&& ($this->source_width $this->source_height)) {
  1900.                     $rotate_angle 90;
  1901.                 elseif (($this->ar == 'P'&& ($this->source_width $this->source_height)) {
  1902.                     $rotate_angle 270;
  1903.                 }
  1904.  
  1905.             }
  1906.             if ($rotate_angle 90{
  1907.                 $this->is_alpha true;
  1908.             }
  1909.             phpthumb_filters::ImprovedImageRotate($this->gdimg_source$rotate_angle$this->config_background_hexcolor$this->bg);
  1910.             $this->source_width  ImageSX($this->gdimg_source);
  1911.             $this->source_height ImageSY($this->gdimg_source);
  1912.         }
  1913.         return true;
  1914.     }
  1915.  
  1916.  
  1917.     function FixedAspectRatio({
  1918.         // optional fixed-dimension images (regardless of aspect ratio)
  1919.  
  1920.         if (!$this->far{
  1921.             // do nothing
  1922.             return true;
  1923.         }
  1924.  
  1925.         if (!$this->w || !$this->h{
  1926.             return false;
  1927.         }
  1928.         $this->thumbnail_width  $this->w;
  1929.         $this->thumbnail_height $this->h;
  1930.         $this->is_alpha true;
  1931.         if ($this->thumbnail_image_width >= $this->thumbnail_width{
  1932.  
  1933.             if ($this->w{
  1934.                 $aspectratio $this->thumbnail_image_height $this->thumbnail_image_width;
  1935.                 $this->thumbnail_image_height round($this->thumbnail_image_width $aspectratio);
  1936.                 $this->thumbnail_height ($this->h $this->h $this->thumbnail_image_height);
  1937.             elseif ($this->thumbnail_image_height $this->thumbnail_height{
  1938.                 $this->thumbnail_image_height $this->thumbnail_height;
  1939.                 $this->thumbnail_image_width  round($this->thumbnail_image_height $aspectratio);
  1940.             }
  1941.  
  1942.         else {
  1943.             if ($this->h{
  1944.                 $aspectratio $this->thumbnail_image_width $this->thumbnail_image_height;
  1945.                 $this->thumbnail_image_width round($this->thumbnail_image_height $aspectratio);
  1946.             elseif ($this->thumbnail_image_width $this->thumbnail_width{
  1947.                 $this->thumbnail_image_width $this->thumbnail_width;
  1948.                 $this->thumbnail_image_height  round($this->thumbnail_image_width $aspectratio);
  1949.             }
  1950.  
  1951.         }
  1952.         return true;
  1953.     }
  1954.  
  1955.  
  1956.     function OffsiteDomainIsAllowed($hostname$allowed_domains{
  1957.         static $domain_is_allowed array();
  1958.         $hostname strtolower($hostname);
  1959.         if (!isset($domain_is_allowed[$hostname])) {
  1960.             $domain_is_allowed[$hostnamefalse;
  1961.             foreach ($allowed_domains as $valid_domain{
  1962.                 $starpos strpos($valid_domain'*');
  1963.                 if ($starpos !== false{
  1964.                     $valid_domain substr($valid_domain$starpos 1);
  1965.                     if (eregi($valid_domain.'$'$hostname)) {
  1966.                         $domain_is_allowed[$hostnametrue;
  1967.                         break;
  1968.                     }
  1969.                 else {
  1970.                     if (strtolower($valid_domain=== $hostname{
  1971.                         $domain_is_allowed[$hostnametrue;
  1972.                         break;
  1973.                     }
  1974.                 }
  1975.             }
  1976.         }
  1977.         return $domain_is_allowed[$hostname];
  1978.     }
  1979.  
  1980.  
  1981.     function AntiOffsiteLinking({
  1982.         // Optional anti-offsite hijacking of the thumbnail script
  1983.         $allow true;
  1984.         if ($allow && $this->config_nooffsitelink_enabled && (@$_SERVER['HTTP_REFERER'|| $this->config_nooffsitelink_require_refer)) {
  1985.             $this->DebugMessage('AntiOffsiteLinking() checking $_SERVER[HTTP_REFERER] "'.@$_SERVER['HTTP_REFERER'].'"'__FILE____LINE__);
  1986.             foreach ($this->config_nooffsitelink_valid_domains as $key => $valid_domain{
  1987.                 // $_SERVER['HTTP_HOST'] contains the port number, so strip it out here to make default configuration work
  1988.                 list($clean_domainexplode(':'$valid_domain);
  1989.                 $this->config_nooffsitelink_valid_domains[$key$clean_domain;
  1990.             }
  1991.             $parsed_url phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']);
  1992.             if (!$this->OffsiteDomainIsAllowed(@$parsed_url['host']$this->config_nooffsitelink_valid_domains)) {
  1993.                 $allow false;
  1994.                 $erase   $this->config_nooffsitelink_erase_image;
  1995.                 $message $this->config_nooffsitelink_text_message;
  1996. $this->ErrorImage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(';'$this->config_nooffsitelink_valid_domains).')');
  1997. exit;
  1998.                 $this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(';'$this->config_nooffsitelink_valid_domains).')'__FILE____LINE__);
  1999.             else {
  2000.                 $this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is in $this->config_nooffsitelink_valid_domains ('.implode(';'$this->config_nooffsitelink_valid_domains).')'__FILE____LINE__);
  2001.             }
  2002.         }
  2003.  
  2004.         if ($allow && $this->config_nohotlink_enabled && eregi('^(f|ht)tps?\://'$this->src)) {
  2005.             $parsed_url phpthumb_functions::ParseURLbetter($this->src);
  2006.             //if (!phpthumb_functions::CaseInsensitiveInArray(@$parsed_url['host'], $this->config_nohotlink_valid_domains)) {
  2007.             if ($this->OffsiteDomainIsAllowed(@$parsed_url['host']$this->config_nohotlink_valid_domains)) {
  2008.                 // This domain is not allowed
  2009.                 $allow false;
  2010.                 $erase   $this->config_nohotlink_erase_image;
  2011.                 $message $this->config_nohotlink_text_message;
  2012.                 $this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is NOT in $this->config_nohotlink_valid_domains ('.implode(';'$this->config_nohotlink_valid_domains).')'__FILE____LINE__);
  2013.             else {
  2014.                 $this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is in $this->config_nohotlink_valid_domains ('.implode(';'$this->config_nohotlink_valid_domains).')'__FILE____LINE__);
  2015.             }
  2016.         }
  2017.  
  2018.         if ($allow{
  2019.             $this->DebugMessage('AntiOffsiteLinking() says this is allowed'__FILE____LINE__);
  2020.             return true;
  2021.         }
  2022.  
  2023.         if (!phpthumb_functions::IsHexColor($this->config_error_bgcolor)) {
  2024.             return $this->ErrorImage('Invalid hex color string "'.$this->config_error_bgcolor.'" for $this->config_error_bgcolor');
  2025.         }
  2026.         if (!phpthumb_functions::IsHexColor($this->config_error_textcolor)) {
  2027.             return $this->ErrorImage('Invalid hex color string "'.$this->config_error_textcolor.'" for $this->config_error_textcolor');
  2028.         }
  2029.         if ($erase{
  2030.  
  2031.             return $this->ErrorImage($message$this->thumbnail_width$this->thumbnail_height$this->config_error_bgcolor$this->config_error_textcolor$this->config_error_fontsize);
  2032.  
  2033.         else {
  2034.  
  2035.             if (is_file($this->config_nooffsitelink_watermark_src)) {
  2036.  
  2037.                 if (!include_once(dirname(__FILE__).'/phpthumb.filters.php')) {
  2038.                     $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying watermark'__FILE____LINE__);
  2039.                     return false;
  2040.                 }
  2041.                 $watermark_img $this->ImageCreateFromStringReplacement(file_get_contents($this->config_nooffsitelink_watermark_src));
  2042.                 $phpthumbFilters new phpthumb_filters();
  2043.                 $phpthumbFilters->phpThumbObject &$this;
  2044.                 $opacity 50;
  2045.                 $margin  5;
  2046.                 $phpthumbFilters->WatermarkOverlay($this->gdimg_output$watermark_img'*'$opacity$margin);
  2047.                 ImageDestroy($watermark_img);
  2048.                 unset($phpthumbFilters);
  2049.  
  2050.             else {
  2051.  
  2052.                 $nohotlink_text_array explode("\n"wordwrap($messagefloor($this->thumbnail_width ImageFontWidth($this->config_error_fontsize))"\n"));
  2053.                 $nohotlink_text_color phpthumb_functions::ImageHexColorAllocate($this->gdimg_output$this->config_error_textcolor);
  2054.  
  2055.                 $topoffset round(($this->thumbnail_height (count($nohotlink_text_arrayImageFontHeight($this->config_error_fontsize))) 2);
  2056.  
  2057.                 $rowcounter 0;
  2058.                 $this->DebugMessage('AntiOffsiteLinking() writing '.count($nohotlink_text_array).' lines of text "'.$message.'" (in #'.$this->config_error_textcolor.') on top of image'__FILE____LINE__);
  2059.                 foreach ($nohotlink_text_array as $textline{
  2060.                     $leftoffset max(0round(($this->thumbnail_width (strlen($textlineImageFontWidth($this->config_error_fontsize))) 2));
  2061.                     ImageString($this->gdimg_output$this->config_error_fontsize$leftoffset$topoffset ($rowcounter++ * ImageFontHeight($this->config_error_fontsize))$textline$nohotlink_text_color);
  2062.                 }
  2063.  
  2064.             }
  2065.  
  2066.         }
  2067.         return true;
  2068.     }
  2069.  
  2070.  
  2071.     function AlphaChannelFlatten({
  2072.         if (!$this->is_alpha{
  2073.             // image doesn't have alpha transparency, no need to flatten
  2074.             $this->DebugMessage('skipping AlphaChannelFlatten() because !$this->is_alpha'__FILE____LINE__);
  2075.             return false;
  2076.         }
  2077.         switch ($this->thumbnailFormat{
  2078.             case 'png':
  2079.             case 'ico':
  2080.                 // image has alpha transparency, but output as PNG or ICO which can handle it
  2081.                 $this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'")'__FILE____LINE__);
  2082.                 return false;
  2083.                 break;
  2084.  
  2085.             case 'gif':
  2086.                 // image has alpha transparency, but output as GIF which can handle only single-color transparency
  2087.                 $CurrentImageColorTransparent ImageColorTransparent($this->gdimg_output);
  2088.                 if ($CurrentImageColorTransparent == -1{
  2089.                     // no transparent color defined
  2090.  
  2091.                     if (phpthumb_functions::gd_version(2.0{
  2092.                         $this->DebugMessage('AlphaChannelFlatten() failed because GD version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2093.                         return false;
  2094.                     }
  2095.  
  2096.                     if ($img_alpha_mixdown_dither @ImageCreateTrueColor(ImageSX($this->gdimg_output)ImageSY($this->gdimg_output))) {
  2097.  
  2098.                         for ($i 0$i <= 255$i++{
  2099.                             $dither_color[$iImageColorAllocate($img_alpha_mixdown_dither$i$i$i);
  2100.                         }
  2101.  
  2102.                         // scan through current truecolor image copy alpha channel to temp image as grayscale
  2103.                         for ($x 0$x $this->thumbnail_width$x++{
  2104.                             for ($y 0$y $this->thumbnail_height$y++{
  2105.                                 $PixelColor phpthumb_functions::GetPixelColor($this->gdimg_output$x$y);
  2106.                                 ImageSetPixel($img_alpha_mixdown_dither$x$y$dither_color[($PixelColor['alpha'2)]);
  2107.                             }
  2108.                         }
  2109.  
  2110.                         // dither alpha channel grayscale version down to 2 colors
  2111.                         ImageTrueColorToPalette($img_alpha_mixdown_dithertrue2);
  2112.  
  2113.                         // reduce color palette to 256-1 colors (leave one palette position for transparent color)
  2114.                         ImageTrueColorToPalette($this->gdimg_outputtrue255);
  2115.  
  2116.                         // allocate a new color for transparent color index
  2117.                         $TransparentColor ImageColorAllocate($this->gdimg_output1254253);
  2118.                         ImageColorTransparent($this->gdimg_output$TransparentColor);
  2119.  
  2120.                         // scan through alpha channel image and note pixels with >50% transparency
  2121.                         $TransparentPixels array();
  2122.                         for ($x 0$x $this->thumbnail_width$x++{
  2123.                             for ($y 0$y $this->thumbnail_height$y++{
  2124.                                 $AlphaChannelPixel phpthumb_functions::GetPixelColor($img_alpha_mixdown_dither$x$y);
  2125.                                 if ($AlphaChannelPixel['red'127{
  2126.                                     ImageSetPixel($this->gdimg_output$x$y$TransparentColor);
  2127.                                 }
  2128.                             }
  2129.                         }
  2130.                         ImageDestroy($img_alpha_mixdown_dither);
  2131.  
  2132.                         $this->DebugMessage('AlphaChannelFlatten() set image to 255+1 colors with transparency for GIF output'__FILE____LINE__);
  2133.                         return true;
  2134.  
  2135.                     else {
  2136.                         $this->DebugMessage('AlphaChannelFlatten() failed ImageCreate('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).')'__FILE____LINE__);
  2137.                         return false;
  2138.                     }
  2139.  
  2140.                 else {
  2141.                     // a single transparent color already defined, leave as-is
  2142.                     $this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'") and ImageColorTransparent returned "'.$CurrentImageColorTransparent.'"'__FILE____LINE__);
  2143.                     return true;
  2144.                 }
  2145.                 break;
  2146.         }
  2147.         $this->DebugMessage('continuing AlphaChannelFlatten() for output format "'.$this->thumbnailFormat.'"'__FILE____LINE__);
  2148.         // image has alpha transparency, and is being output in a format that doesn't support it -- flatten
  2149.         if ($gdimg_flatten_temp phpthumb_functions::ImageCreateFunction($this->thumbnail_width$this->thumbnail_height)) {
  2150.  
  2151.             $this->config_background_hexcolor ($this->bg $this->bg $this->config_background_hexcolor);
  2152.             if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
  2153.                 return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
  2154.             }
  2155.             $background_color phpthumb_functions::ImageHexColorAllocate($this->gdimg_output$this->config_background_hexcolor);
  2156.             ImageFilledRectangle($gdimg_flatten_temp00$this->thumbnail_width$this->thumbnail_height$background_color);
  2157.             ImageCopy($gdimg_flatten_temp$this->gdimg_output0000$this->thumbnail_width$this->thumbnail_height);
  2158.  
  2159.             ImageAlphaBlending($this->gdimg_outputtrue);
  2160.             ImageSaveAlpha($this->gdimg_outputfalse);
  2161.             ImageColorTransparent($this->gdimg_output-1);
  2162.             ImageCopy($this->gdimg_output$gdimg_flatten_temp0000$this->thumbnail_width$this->thumbnail_height);
  2163.  
  2164.             ImageDestroy($gdimg_flatten_temp);
  2165.             return true;
  2166.  
  2167.         else {
  2168.             $this->DebugMessage('ImageCreateFunction() failed'__FILE____LINE__);
  2169.         }
  2170.         return false;
  2171.     }
  2172.  
  2173.  
  2174.     function ApplyFilters({
  2175.         if ($this->fltr && is_array($this->fltr)) {
  2176.             if (!include_once(dirname(__FILE__).'/phpthumb.filters.php')) {
  2177.                 $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';'$this->fltr).')'__FILE____LINE__);
  2178.                 return false;
  2179.             }
  2180.             $phpthumbFilters new phpthumb_filters();
  2181.             $phpthumbFilters->phpThumbObject &$this;
  2182.             foreach ($this->fltr as $filtercommand{
  2183.                 @list($command$parameterexplode('|'$filtercommand2);
  2184.                 $this->DebugMessage('Attempting to process filter command "'.$command.'('.$parameter.')"'__FILE____LINE__);
  2185.                 switch ($command{
  2186.                     case 'brit'// Brightness
  2187.                         $phpthumbFilters->Brightness($this->gdimg_output$parameter);
  2188.                         break;
  2189.  
  2190.                     case 'cont'// Contrast
  2191.                         $phpthumbFilters->Contrast($this->gdimg_output$parameter);
  2192.                         break;
  2193.  
  2194.                     case 'ds'// Desaturation
  2195.                         $phpthumbFilters->Desaturate($this->gdimg_output$parameter'');
  2196.                         break;
  2197.  
  2198.                     case 'sat'// Saturation
  2199.                         $phpthumbFilters->Saturation($this->gdimg_output$parameter'');
  2200.                         break;
  2201.  
  2202.                     case 'gray'// Grayscale
  2203.                         $phpthumbFilters->Grayscale($this->gdimg_output);
  2204.                         break;
  2205.  
  2206.                     case 'clr'// Colorize
  2207.                         if (phpthumb_functions::gd_version(2{
  2208.                             $this->DebugMessage('Skipping Colorize() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2209.                             break;
  2210.                         }
  2211.                         @list($amount$colorexplode('|'$parameter);
  2212.                         $phpthumbFilters->Colorize($this->gdimg_output$amount$color);
  2213.                         break;
  2214.  
  2215.                     case 'sep'// Sepia
  2216.                         if (phpthumb_functions::gd_version(2{
  2217.                             $this->DebugMessage('Skipping Sepia() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2218.                             break;
  2219.                         }
  2220.                         @list($amount$colorexplode('|'$parameter);
  2221.                         $phpthumbFilters->Sepia($this->gdimg_output$amount$color);
  2222.                         break;
  2223.  
  2224.                     case 'gam'// Gamma correction
  2225.                         $phpthumbFilters->Gamma($this->gdimg_output$parameter);
  2226.                         break;
  2227.  
  2228.                     case 'neg'// Negative colors
  2229.                         $phpthumbFilters->Negative($this->gdimg_output);
  2230.                         break;
  2231.  
  2232.                     case 'th'// Threshold
  2233.                         $phpthumbFilters->Threshold($this->gdimg_output$parameter);
  2234.                         break;
  2235.  
  2236.                     case 'rcd'// ReduceColorDepth
  2237.                         if (phpthumb_functions::gd_version(2{
  2238.                             $this->DebugMessage('Skipping ReduceColorDepth() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2239.                             break;
  2240.                         }
  2241.                         @list($colors$ditherexplode('|'$parameter);
  2242.                         $colors ($colors                ?  (int) $colors 256);
  2243.                         $dither  ((strlen($dither0? (bool) $dither true);
  2244.                         $phpthumbFilters->ReduceColorDepth($this->gdimg_output$colors$dither);
  2245.                         break;
  2246.  
  2247.                     case 'flip'// Flip
  2248.                         $phpthumbFilters->Flip($this->gdimg_output(strpos(strtolower($parameter)'x'!== false)(strpos(strtolower($parameter)'y'!== false));
  2249.                         break;
  2250.  
  2251.                     case 'edge'// EdgeDetect
  2252.                         $phpthumbFilters->EdgeDetect($this->gdimg_output);
  2253.                         break;
  2254.  
  2255.                     case 'emb'// Emboss
  2256.                         $phpthumbFilters->Emboss($this->gdimg_output);
  2257.                         break;
  2258.  
  2259.                     case 'bvl'// Bevel
  2260.                         @list($width$color1$color2explode('|'$parameter);
  2261.                         $phpthumbFilters->Bevel($this->gdimg_output$width$color1$color2);
  2262.                         break;
  2263.  
  2264.                     case 'lvl'// autoLevels
  2265.                         @list($band$method$thresholdexplode('|'$parameter);
  2266.                         $band      ($band ereg_replace('[^RGBA\\*]'''strtoupper($band)) '*');
  2267.                         $method    ((strlen($method0)    intval($method)                :   2);
  2268.                         $threshold ((strlen($threshold0floatval($threshold)           0.1);
  2269.  
  2270.                         $phpthumbFilters->HistogramStretch($this->gdimg_output$band$method$threshold);
  2271.                         break;
  2272.  
  2273.                     case 'wb'// WhiteBalance
  2274.                         $phpthumbFilters->WhiteBalance($this->gdimg_output$parameter);
  2275.                         break;
  2276.  
  2277.                     case 'hist'// Histogram overlay
  2278.                         if (phpthumb_functions::gd_version(2{
  2279.                             $this->DebugMessage('Skipping HistogramOverlay() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2280.                             break;
  2281.                         }
  2282.                         @list($bands$colors$width$height$alignment$opacity$margin_x$margin_yexplode('|'$parameter);
  2283.                         $bands     ($bands     $bands     :  '*');
  2284.                         $colors    ($colors    $colors    :   '');
  2285.                         $width     ($width     $width     0.25);
  2286.                         $height    ($height    $height    0.25);
  2287.                         $alignment ($alignment $alignment 'BR');
  2288.                         $opacity   ($opacity   $opacity   :   50);
  2289.                         $margin_x  ($margin_x  $margin_x  :    5);
  2290.                         $margin_y  $margin_y// just to note it wasn't forgotten, but let the value always pass unchanged
  2291.                         $phpthumbFilters->HistogramOverlay($this->gdimg_output$bands$colors$width$height$alignment$opacity$margin_x$margin_y);
  2292.                         break;
  2293.  
  2294.                     case 'fram'// Frame
  2295.                         @list($frame_width$edge_width$color_frame$color1$color2explode('|'$parameter);
  2296.                         $phpthumbFilters->Frame($this->gdimg_output$frame_width$edge_width$color_frame$color1$color2);
  2297.                         break;
  2298.  
  2299.                     case 'drop'// DropShadow
  2300.                         if (phpthumb_functions::gd_version(2{
  2301.                             $this->DebugMessage('Skipping DropShadow() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2302.                             return false;
  2303.                         }
  2304.                         $this->is_alpha true;
  2305.                         @list($distance$width$color$angle$fadeexplode('|'$parameter);
  2306.                         $phpthumbFilters->DropShadow($this->gdimg_output$distance$width$color$angle$fade);
  2307.                         break;
  2308.  
  2309.                     case 'mask'// Mask cropping
  2310.                         if (phpthumb_functions::gd_version(2{
  2311.                             $this->DebugMessage('Skipping Mask() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2312.                             return false;
  2313.                         }
  2314.                         $mask_filename $this->ResolveFilenameToAbsolute($parameter);
  2315.                         if (@is_readable($mask_filename&& ($fp_mask @fopen($mask_filename'rb'))) {
  2316.                             $MaskImageData '';
  2317.                             do {
  2318.                                 $buffer fread($fp_mask8192);
  2319.                                 $MaskImageData .= $buffer;
  2320.                             while (strlen($buffer0);
  2321.                             fclose($fp_mask);
  2322.                             if ($gdimg_mask $this->ImageCreateFromStringReplacement($MaskImageData)) {
  2323.                                 $this->is_alpha true;
  2324.                                 $phpthumbFilters->ApplyMask($gdimg_mask$this->gdimg_output);
  2325.                                 ImageDestroy($gdimg_mask);
  2326.                             else {
  2327.                                 $this->DebugMessage('ImageCreateFromStringReplacement() failed for "'.$mask_filename.'"'__FILE____LINE__);
  2328.                             }
  2329.                         else {
  2330.                             $this->DebugMessage('Cannot open mask file "'.$mask_filename.'"'__FILE____LINE__);
  2331.                         }
  2332.                         break;
  2333.  
  2334.                     case 'elip'// Elipse cropping
  2335.                         if (phpthumb_functions::gd_version(2{
  2336.                             $this->DebugMessage('Skipping Elipse() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2337.                             return false;
  2338.                         }
  2339.                         $this->is_alpha true;
  2340.                         $phpthumbFilters->Elipse($this->gdimg_output);
  2341.                         break;
  2342.  
  2343.                     case 'ric'// RoundedImageCorners
  2344.                         if (phpthumb_functions::gd_version(2{
  2345.                             $this->DebugMessage('Skipping RoundedImageCorners() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2346.                             return false;
  2347.                         }
  2348.                         @list($radius_x$radius_yexplode('|'$parameter);
  2349.                         if (($radius_x 1|| ($radius_y 1)) {
  2350.                             $this->DebugMessage('Skipping RoundedImageCorners('.$radius_x.', '.$radius_y.') because x/y radius is less than 1'__FILE____LINE__);
  2351.                             break;
  2352.                         }
  2353.                         $this->is_alpha true;
  2354.                         $phpthumbFilters->RoundedImageCorners($this->gdimg_output$radius_x$radius_y);
  2355.                         break;
  2356.  
  2357.                     case 'crop'// Crop
  2358.                         @list($left$right$top$bottomexplode('|'$parameter);
  2359.                         $phpthumbFilters->Crop($this->gdimg_output$left$right$top$bottom);
  2360.                         break;
  2361.  
  2362.                     case 'bord'// Border
  2363.                         @list($border_width$radius_x$radius_y$hexcolor_borderexplode('|'$parameter);
  2364.                         $this->is_alpha true;
  2365.                         $phpthumbFilters->ImageBorder($this->gdimg_output$border_width$radius_x$radius_y$hexcolor_border);
  2366.                         break;
  2367.  
  2368.                     case 'over'// Overlay
  2369.                         @list($filename$underlay$margin$opacityexplode('|'$parameter);
  2370.                         $underlay = (bool) ($underlay              $underlay false);
  2371.                         $margin   =        ((strlen($margin)  0$margin   ($underlay 0.1 0.0));
  2372.                         $opacity  =        ((strlen($opacity0$opacity  100);
  2373.                         if (($margin 0&& ($margin 1)) {
  2374.                             $margin min(0.499$margin);
  2375.                         elseif (($margin > -1&& ($margin 0)) {
  2376.                             $margin max(-0.499$margin);
  2377.                         }
  2378.  
  2379.                         $filename $this->ResolveFilenameToAbsolute($filename);
  2380.                         if (@is_readable($filename&& ($fp_watermark @fopen($filename'rb'))) {
  2381.                             $WatermarkImageData '';
  2382.                             do {
  2383.                                 $buffer fread($fp_watermark8192);
  2384.                                 $WatermarkImageData .= $buffer;
  2385.                             while (strlen($buffer0);
  2386.                             fclose($fp_watermark);
  2387.                             if ($img_watermark $this->ImageCreateFromStringReplacement($WatermarkImageData)) {
  2388.                                 if ($margin 1{
  2389.                                     $resized_x max(1ImageSX($this->gdimg_outputround((ImageSX($this->gdimg_output$margin)));
  2390.                                     $resized_y max(1ImageSY($this->gdimg_outputround((ImageSY($this->gdimg_output$margin)));
  2391.                                 else {
  2392.                                     $resized_x max(1ImageSX($this->gdimg_outputround($margin));
  2393.                                     $resized_y max(1ImageSY($this->gdimg_outputround($margin));
  2394.                                 }
  2395.  
  2396.                                 if ($underlay{
  2397.  
  2398.                                     if ($img_watermark_resized phpthumb_functions::ImageCreateFunction(ImageSX($this->gdimg_output)ImageSY($this->gdimg_output))) {
  2399.                                         ImageAlphaBlending($img_watermark_resizedfalse);
  2400.                                         ImageSaveAlpha($img_watermark_resizedtrue);
  2401.                                         $this->ImageResizeFunction($img_watermark_resized$img_watermark0000ImageSX($img_watermark_resized)ImageSY($img_watermark_resized)ImageSX($img_watermark)ImageSY($img_watermark));
  2402.                                         if ($img_source_resized phpthumb_functions::ImageCreateFunction($resized_x$resized_y)) {
  2403.                                             ImageAlphaBlending($img_source_resizedfalse);
  2404.                                             ImageSaveAlpha($img_source_resizedtrue);
  2405.                                             $this->ImageResizeFunction($img_source_resized$this->gdimg_output0000ImageSX($img_source_resized)ImageSY($img_source_resized)ImageSX($this->gdimg_output)ImageSY($this->gdimg_output));
  2406.                                             $phpthumbFilters->WatermarkOverlay($img_watermark_resized$img_source_resized'C'$opacity$margin);
  2407.                                             ImageCopy($this->gdimg_output$img_watermark_resized0000ImageSX($this->gdimg_output)ImageSY($this->gdimg_output));
  2408.                                         else {
  2409.                                             $this->DebugMessage('phpthumb_functions::ImageCreateFunction('.$resized_x.', '.$resized_y.')'__FILE____LINE__);
  2410.                                         }
  2411.                                         ImageDestroy($img_watermark_resized);
  2412.                                     else {
  2413.                                         $this->DebugMessage('phpthumb_functions::ImageCreateFunction('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).')'__FILE____LINE__);
  2414.                                     }
  2415.  
  2416.                                 else // overlay
  2417.  
  2418.                                     if ($img_watermark_resized phpthumb_functions::ImageCreateFunction($resized_x$resized_y)) {
  2419.                                         ImageAlphaBlending($img_watermark_resizedfalse);
  2420.                                         ImageSaveAlpha($img_watermark_resizedtrue);
  2421.                                         $this->ImageResizeFunction($img_watermark_resized$img_watermark0000ImageSX($img_watermark_resized)ImageSY($img_watermark_resized)ImageSX($img_watermark)ImageSY($img_watermark));
  2422.                                         $phpthumbFilters->WatermarkOverlay($this->gdimg_output$img_watermark_resized'C'$opacity$margin);
  2423.                                         ImageDestroy($img_watermark_resized);
  2424.                                     else {
  2425.                                         $this->DebugMessage('phpthumb_functions::ImageCreateFunction('.$resized_x.', '.$resized_y.')'__FILE____LINE__);
  2426.                                     }
  2427.  
  2428.                                 }
  2429.                                 ImageDestroy($img_watermark);
  2430.  
  2431.                             else {
  2432.                                 $this->DebugMessage('ImageCreateFromStringReplacement() failed for "'.$filename.'"'__FILE____LINE__);
  2433.                             }
  2434.                         else {
  2435.                             $this->DebugMessage('Cannot open overlay file "'.$filename.'"'__FILE____LINE__);
  2436.                         }
  2437.                         break;
  2438.  
  2439.                     case 'wmi'// WaterMarkImage
  2440.                         @list($filename$alignment$opacity$margin['x']$margin['y']$rotate_angleexplode('|'$parameter);
  2441.                         // $margin can be pixel margin or percent margin if $alignment is text, or max width/height if $alignment is position like "50x75"
  2442.                         $alignment    ($alignment            $alignment            'BR');
  2443.                         $opacity      (strlen($opacity)      intval($opacity)      50);
  2444.                         $rotate_angle (strlen($rotate_angleintval($rotate_angle0);
  2445.                         if (!eregi('^([0-9\\.\\-]*)x([0-9\\.\\-]*)$'$alignment$matches)) {
  2446.                             $margins array('x''y');
  2447.                             foreach ($margins as $xy{
  2448.                                 $margin[$xy(strlen($margin[$xy]$margin[$xy5);
  2449.                                 if (($margin[$xy0&& ($margin[$xy1)) {
  2450.                                     $margin[$xymin(0.499$margin[$xy]);
  2451.                                 elseif (($margin[$xy> -1&& ($margin[$xy0)) {
  2452.                                     $margin[$xymax(-0.499$margin[$xy]);
  2453.                                 }
  2454.                             }
  2455.                         }
  2456.  
  2457.                         $filename $this->ResolveFilenameToAbsolute($filename);
  2458.                         if (@is_readable($filename)) {
  2459.                             if ($img_watermark $this->ImageCreateFromFilename($filename)) {
  2460.                                 if ($rotate_angle !== 0{
  2461.                                     $phpthumbFilters->ImprovedImageRotate($img_watermark$rotate_angle);
  2462.                                 }
  2463.                                 if (eregi('^([0-9\\.\\-]*)x([0-9\\.\\-]*)$'$alignment$matches)) {
  2464.                                     $watermark_max_width  intval($margin['x'$margin['x'ImageSX($img_watermark));
  2465.                                     $watermark_max_height intval($margin['y'$margin['y'ImageSY($img_watermark));
  2466.                                     $scale phpthumb_functions::ScaleToFitInBox(ImageSX($img_watermark)ImageSY($img_watermark)$watermark_max_width$watermark_max_heighttruetrue);
  2467.                                     $this->DebugMessage('Scaling watermark by a factor of '.number_format($scale4)__FILE____LINE__);
  2468.                                     if (($scale 1|| ($scale 1)) {
  2469.                                         if ($img_watermark2 phpthumb_functions::ImageCreateFunction($scale ImageSX($img_watermark)$scale ImageSY($img_watermark))) {
  2470.                                             ImageAlphaBlending($img_watermark2false);
  2471.                                             ImageSaveAlpha($img_watermark2true);
  2472.                                             $this->ImageResizeFunction($img_watermark2$img_watermark0000ImageSX($img_watermark2)ImageSY($img_watermark2)ImageSX($img_watermark)ImageSY($img_watermark));
  2473.                                             $img_watermark $img_watermark2;
  2474.                                         else {
  2475.                                             $this->DebugMessage('ImageCreateFunction('.($scale ImageSX($img_watermark)).', '.($scale ImageSX($img_watermark)).') failed'__FILE____LINE__);
  2476.                                         }
  2477.                                     }
  2478.                                     $watermark_dest_x round($matches[1(ImageSX($img_watermark2));
  2479.                                     $watermark_dest_y round($matches[2(ImageSY($img_watermark2));
  2480.                                     $alignment $watermark_dest_x.'x'.$watermark_dest_y;
  2481.                                 }
  2482.                                 $phpthumbFilters->WatermarkOverlay($this->gdimg_output$img_watermark$alignment$opacity$margin['x']$margin['y']);
  2483.                                 ImageDestroy($img_watermark);
  2484.                                 if (isset($img_watermark2&& is_resource($img_watermark2)) {
  2485.                                     ImageDestroy($img_watermark2);
  2486.                                 }
  2487.                             else {
  2488.                                 $this->DebugMessage('ImageCreateFromFilename() failed for "'.$filename.'"'__FILE____LINE__);
  2489.                             }
  2490.                         else {
  2491.                             $this->DebugMessage('!is_readable('.$filename.')'__FILE____LINE__);
  2492.                         }
  2493.                         break;
  2494.  
  2495.                     case 'wmt'// WaterMarkText
  2496.                         @list($text$size$alignment$hex_color$ttffont$opacity$margin$angle$bg_color$bg_opacity$fillextendexplode('|'$parameter);
  2497.                         $text       ($text            $text       '');
  2498.                         $size       ($size            $size       3);
  2499.                         $alignment  ($alignment       $alignment  'BR');
  2500.                         $hex_color  ($hex_color       $hex_color  '000000');
  2501.                         $ttffont    ($ttffont         $ttffont    '');
  2502.                         $opacity    (strlen($opacity$opacity    50);
  2503.                         $margin     (strlen($margin)  $margin     5);
  2504.                         $angle      (strlen($angle)   $angle      0);
  2505.                         $bg_color   ($bg_color        $bg_color   false);
  2506.                         $bg_opacity ($bg_opacity      $bg_opacity 0);
  2507.                         $fillextend ($fillextend      $fillextend '');
  2508.  
  2509.                         if (basename($ttffont== $ttffont{
  2510.                             $ttffont realpath($this->config_ttf_directory.DIRECTORY_SEPARATOR.$ttffont);
  2511.                         else {
  2512.                             $ttffont $this->ResolveFilenameToAbsolute($ttffont);
  2513.                         }
  2514.                         $phpthumbFilters->WatermarkText($this->gdimg_output$text$size$alignment$hex_color$ttffont$opacity$margin$angle$bg_color$bg_opacity$fillextend);
  2515.                         break;
  2516.  
  2517.                     case 'blur'// Blur
  2518.                         @list($radiusexplode('|'$parameter);
  2519.                         $radius ($radius $radius 1);
  2520.                         if (phpthumb_functions::gd_version(>= 2{
  2521.                             $phpthumbFilters->Blur($this->gdimg_output$radius);
  2522.                         else {
  2523.                             $this->DebugMessage('Skipping Blur() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2524.                             //return false;
  2525.                         }
  2526.                         break;
  2527.  
  2528.                     case 'size'// Resize
  2529.                         @list($newwidth$newheight$stretchexplode('|'$parameter);
  2530.                         $newwidth  (!$newwidth  ImageSX($this->gdimg_output((($newwidth  0&& ($newwidth  1)) round($newwidth  ImageSX($this->gdimg_output)) round($newwidth)));
  2531.                         $newheight (!$newheight ImageSY($this->gdimg_output((($newheight 0&& ($newheight 1)) round($newheight ImageSY($this->gdimg_output)) round($newheight)));
  2532.                         $stretch   ($stretch true false);
  2533.                         if ($stretch{
  2534.                             $scale_x phpthumb_functions::ScaleToFitInBox(ImageSX($this->gdimg_output)ImageSX($this->gdimg_output)$newwidth,  $newwidth,  truetrue);
  2535.                             $scale_y phpthumb_functions::ScaleToFitInBox(ImageSY($this->gdimg_output)ImageSY($this->gdimg_output)$newheight$newheighttruetrue);
  2536.                         else {
  2537.                             $scale_x phpthumb_functions::ScaleToFitInBox(ImageSX($this->gdimg_output)ImageSY($this->gdimg_output)$newwidth$newheighttruetrue);
  2538.                             $scale_y $scale_x;
  2539.                         }
  2540.                         $this->DebugMessage('Scaling watermark ('.($stretch 'with' 'without').' stretch) by a factor of "'.number_format($scale_x4).' x '.number_format($scale_y4).'"'__FILE____LINE__);
  2541.                         if (($scale_x 1|| ($scale_x 1|| ($scale_y 1|| ($scale_y 1)) {
  2542.                             if ($img_temp phpthumb_functions::ImageCreateFunction(ImageSX($this->gdimg_output)ImageSY($this->gdimg_output))) {
  2543.                                 ImageCopy($img_temp$this->gdimg_output0000ImageSX($this->gdimg_output)ImageSY($this->gdimg_output));
  2544.                                 //ImageDestroy($this->gdimg_output);
  2545.                                 if ($this->gdimg_output phpthumb_functions::ImageCreateFunction($scale_x ImageSX($img_temp)$scale_y ImageSY($img_temp))) {
  2546.                                     ImageAlphaBlending($this->gdimg_outputfalse);
  2547.                                     ImageSaveAlpha($this->gdimg_outputtrue);
  2548.                                     $this->ImageResizeFunction($this->gdimg_output$img_temp0000ImageSX($this->gdimg_output)ImageSY($this->gdimg_output)ImageSX($img_temp)ImageSY($img_temp));
  2549.                                 else {
  2550.                                     $this->DebugMessage('ImageCreateFunction('.($scale_x ImageSX($img_temp)).', '.($scale_y ImageSY($img_temp)).') failed'__FILE____LINE__);
  2551.                                 }
  2552.                                 ImageDestroy($img_temp);
  2553.                             else {
  2554.                                 $this->DebugMessage('ImageCreateFunction('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).') failed'__FILE____LINE__);
  2555.                             }
  2556.                         }
  2557.                         break;
  2558.  
  2559.                     case 'gblr'// Gaussian Blur
  2560.                         $phpthumbFilters->BlurGaussian($this->gdimg_output);
  2561.                         break;
  2562.  
  2563.                     case 'sblr'// Selective Blur
  2564.                         $phpthumbFilters->BlurSelective($this->gdimg_output);
  2565.                         break;
  2566.  
  2567.                     case 'mean'// MeanRemoval blur
  2568.                         $phpthumbFilters->MeanRemoval($this->gdimg_output);
  2569.                         break;
  2570.  
  2571.                     case 'smth'// Smooth blur
  2572.                         $phpthumbFilters->Smooth($this->gdimg_output$parameter);
  2573.                         break;
  2574.  
  2575.                     case 'usm'// UnSharpMask sharpening
  2576.                         @list($amount$radius$thresholdexplode('|'$parameter);
  2577.                         $amount    ($amount            $amount    80);
  2578.                         $radius    ($radius            $radius    0.5);
  2579.                         $threshold (strlen($threshold$threshold 3);
  2580.                         if (phpthumb_functions::gd_version(>= 2.0{
  2581.                             ob_start();
  2582.                             if (!@include_once(dirname(__FILE__).'/phpthumb.unsharp.php')) {
  2583.                                 $include_error ob_get_contents();
  2584.                                 if ($include_error{
  2585.                                     $this->DebugMessage('include_once("'.dirname(__FILE__).'/phpthumb.unsharp.php") generated message: "'.$include_error.'"'__FILE____LINE__);
  2586.                                 }
  2587.                                 $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.unsharp.php" which is required for unsharp masking'__FILE____LINE__);
  2588.                                 ob_end_clean();
  2589.                                 return false;
  2590.                             }
  2591.                             ob_end_clean();
  2592.                             phpUnsharpMask::applyUnsharpMask($this->gdimg_output$amount$radius$threshold);
  2593.                         else {
  2594.                             $this->DebugMessage('Skipping unsharp mask because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2595.                             return false;
  2596.                         }
  2597.                         break;
  2598.  
  2599.                     case 'rot'// ROTate
  2600.                         @list($angle$bgcolorexplode('|'$parameter);
  2601.                         $phpthumbFilters->ImprovedImageRotate($this->gdimg_output$angle$bgcolor);
  2602.                         break;
  2603.  
  2604.                     case 'stc'// Source Transparent Color
  2605.                         @list($hexcolor$min_limit$max_limitexplode('|'$parameter);
  2606.                         if (!phpthumb_functions::IsHexColor($hexcolor)) {
  2607.                             $this->DebugMessage('Skipping SourceTransparentColor hex color is invalid ('.$hexcolor.')'__FILE____LINE__);
  2608.                             return false;
  2609.                         }
  2610.                         $min_limit (strlen($min_limit$min_limit :  5);
  2611.                         $max_limit (strlen($max_limit$max_limit 10);
  2612.                         if ($gdimg_mask $phpthumbFilters->SourceTransparentColorMask($this->gdimg_output$hexcolor$min_limit$max_limit)) {
  2613.                             $this->is_alpha true;
  2614.                             $phpthumbFilters->ApplyMask($gdimg_mask$this->gdimg_output);
  2615.                             ImageDestroy($gdimg_mask);
  2616.                         else {
  2617.                             $this->DebugMessage('SourceTransparentColorMask() failed for "'.$mask_filename.'"'__FILE____LINE__);
  2618.                         }
  2619.                         break;
  2620.                 }
  2621.                 $this->DebugMessage('Finished processing filter command "'.$command.'('.$parameter.')"'__FILE____LINE__);
  2622.             }
  2623.         }
  2624.         return true;
  2625.     }
  2626.  
  2627.  
  2628.     function MaxFileSize({
  2629.         if (phpthumb_functions::gd_version(2{
  2630.             $this->DebugMessage('Skipping MaxFileSize() because gd_version is "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  2631.             return false;
  2632.         }
  2633.         if ($this->maxb 0{
  2634.             switch ($this->thumbnailFormat{
  2635.                 case 'png':
  2636.                 case 'gif':
  2637.                     $imgRenderFunction 'image'.$this->thumbnailFormat;
  2638.  
  2639.                     ob_start();
  2640.                     $imgRenderFunction($this->gdimg_output);
  2641.                     $imgdata ob_get_contents();
  2642.                     ob_end_clean();
  2643.  
  2644.                     if (strlen($imgdata$this->maxb{
  2645.                         for ($i 8$i >= 1$i--{
  2646.                             $tempIMG ImageCreateTrueColor(ImageSX($this->gdimg_output)ImageSY($this->gdimg_output));
  2647.                             ImageCopy($tempIMG$this->gdimg_output0000ImageSX($this->gdimg_output)ImageSY($this->gdimg_output));
  2648.                             ImageTrueColorToPalette($tempIMGtruepow(2$i));
  2649.                             ob_start();
  2650.                             $imgRenderFunction($tempIMG);
  2651.                             $imgdata ob_get_contents();
  2652.                             ob_end_clean();
  2653.  
  2654.                             if (strlen($imgdata<= $this->maxb{
  2655.                                 ImageTrueColorToPalette($this->gdimg_outputtruepow(2$i));
  2656.                                 break;
  2657.                             }
  2658.                         }
  2659.                     }
  2660.                     if (strlen($imgdata$this->maxb{
  2661.                         ImageTrueColorToPalette($this->gdimg_outputtruepow(2$i));
  2662.                         return false;
  2663.                     }
  2664.                     break;
  2665.  
  2666.                 case 'jpeg':
  2667.                     ob_start();
  2668.                     ImageJPEG($this->gdimg_output);
  2669.                     $imgdata ob_get_contents();
  2670.                     ob_end_clean();
  2671.  
  2672.                     $OriginalJPEGquality $this->thumbnailQuality;
  2673.                     if (strlen($imgdata$this->maxb{
  2674.                         for ($i 3$i 20$i++{
  2675.                             $q round(100 (log10($i 2)));
  2676.                             ob_start();
  2677.                             ImageJPEG($this->gdimg_output''$q);
  2678.                             $imgdata ob_get_contents();
  2679.                             ob_end_clean();
  2680.  
  2681.                             $this->thumbnailQuality $q;
  2682.                             if (strlen($imgdata<= $this->maxb{
  2683.                                 break;
  2684.                             }
  2685.                         }
  2686.                     }
  2687.                     if (strlen($imgdata$this->maxb{
  2688.                         return false;
  2689.                     }
  2690.                     break;
  2691.  
  2692.                 default:
  2693.                     return false;
  2694.                     break;
  2695.             }
  2696.         }
  2697.         return true;
  2698.     }
  2699.  
  2700.  
  2701.     function CalculateThumbnailDimensions({
  2702. //echo $this->source_width.'x'.$this->source_height.'<hr>';
  2703.         $this->thumbnailCropX ($this->sx (($this->sx >= 1$this->sx round($this->sx $this->source_width))  0);
  2704. //echo $this->thumbnailCropX.'<br>';
  2705.         $this->thumbnailCropY ($this->sy (($this->sy >= 1$this->sy round($this->sy $this->source_height)) 0);
  2706. //echo $this->thumbnailCropY.'<br>';
  2707.         $this->thumbnailCropW ($this->sw (($this->sw >= 1$this->sw round($this->sw $this->source_width))  $this->source_width);
  2708. //echo $this->thumbnailCropW.'<br>';
  2709.         $this->thumbnailCropH ($this->sh (($this->sh >= 1$this->sh round($this->sh $this->source_height)) $this->source_height);
  2710. //echo $this->thumbnailCropH.'<hr>';
  2711.  
  2712.         // limit source area to original image area
  2713.         $this->thumbnailCropW max(1min($this->thumbnailCropW$this->source_width  $this->thumbnailCropX));
  2714.         $this->thumbnailCropH max(1min($this->thumbnailCropH$this->source_height $this->thumbnailCropY));
  2715.  
  2716.         $this->DebugMessage('CalculateThumbnailDimensions() [x,y,w,h] initially set to ['.$this->thumbnailCropX.','.$this->thumbnailCropY.','.$this->thumbnailCropW.','.$this->thumbnailCropH.']'__FILE____LINE__);
  2717.  
  2718.  
  2719.         if ($this->zc && $this->w && $this->h{
  2720.             // Zoom Crop
  2721.             // retain proportional resizing we did above, but crop off larger dimension so smaller
  2722.             // dimension fully fits available space
  2723.  
  2724.             $scaling_X $this->source_width  $this->w;
  2725.             $scaling_Y $this->source_height $this->h;
  2726.             if ($scaling_X $scaling_Y{
  2727.                 // some of the width will need to be cropped
  2728.                 $allowable_width $this->source_width $scaling_X $scaling_Y;
  2729.                 $this->thumbnailCropW round($allowable_width);
  2730.                 $this->thumbnailCropX round(($this->source_width $allowable_width2);
  2731.  
  2732.             elseif ($scaling_Y $scaling_X{
  2733.                 // some of the height will need to be cropped
  2734.                 $allowable_height $this->source_height $scaling_Y $scaling_X;
  2735.                 $this->thumbnailCropH round($allowable_height);
  2736.                 $this->thumbnailCropY round(($this->source_height $allowable_height2);
  2737.  
  2738.             else {
  2739.                 // image fits perfectly, no cropping needed
  2740.             }
  2741.             $this->thumbnail_width  $this->w;
  2742.             $this->thumbnail_height $this->h;
  2743.             $this->thumbnail_image_width  $this->thumbnail_width;
  2744.             $this->thumbnail_image_height $this->thumbnail_height;
  2745.  
  2746.         elseif ($this->iar && $this->w && $this->h{
  2747.  
  2748.             // Ignore Aspect Ratio
  2749.             // stretch image to fit exactly 'w' x 'h'
  2750.             $this->thumbnail_width  $this->w;
  2751.             $this->thumbnail_height $this->h;
  2752.             $this->thumbnail_image_width  $this->thumbnail_width;
  2753.             $this->thumbnail_image_height $this->thumbnail_height;
  2754.  
  2755.         else {
  2756.  
  2757.             $original_aspect_ratio $this->thumbnailCropW $this->thumbnailCropH;
  2758.             if ($this->aoe{
  2759.                 if ($this->w && $this->h{
  2760.                     $maxwidth  min($this->w$this->h $original_aspect_ratio);
  2761.                     $maxheight min($this->h$this->w $original_aspect_ratio);
  2762.                 elseif ($this->w{
  2763.                     $maxwidth  $this->w;
  2764.                     $maxheight $this->w $original_aspect_ratio;
  2765.                 elseif ($this->h{
  2766.                     $maxwidth  $this->h $original_aspect_ratio;
  2767.                     $maxheight $this->h;
  2768.                 else {
  2769.                     $maxwidth  $this->thumbnailCropW;
  2770.                     $maxheight $this->thumbnailCropH;
  2771.                 }
  2772.             else {
  2773.                 $maxwidth  phpthumb_functions::nonempty_min($this->w$this->thumbnailCropW$this->config_output_maxwidth);
  2774.                 $maxheight phpthumb_functions::nonempty_min($this->h$this->thumbnailCropH$this->config_output_maxheight);
  2775. //echo $maxwidth.'x'.$maxheight.'<br>';
  2776.                 $maxwidth  min($maxwidth$maxheight $original_aspect_ratio);
  2777.                 $maxheight min($maxheight$maxwidth $original_aspect_ratio);
  2778. //echo $maxwidth.'x'.$maxheight.'<hr>';
  2779.             }
  2780.  
  2781.             $this->thumbnail_image_width  $maxwidth;
  2782.             $this->thumbnail_image_height $maxheight;
  2783.             $this->thumbnail_width  $maxwidth;
  2784.             $this->thumbnail_height $maxheight;
  2785.  
  2786.             $this->FixedAspectRatio();
  2787.         }
  2788.  
  2789.         $this->thumbnail_width  max(1floor($this->thumbnail_width));
  2790.         $this->thumbnail_height max(1floor($this->thumbnail_height));
  2791.         return true;
  2792.     }
  2793.  
  2794.  
  2795.     function CreateGDoutput({
  2796.         $this->CalculateThumbnailDimensions();
  2797.  
  2798.         // Create the GD image (either true-color or 256-color, depending on GD version)
  2799.  
  2800.         // Images that have transparency must have the background filled with the configured 'bg' color
  2801.         // otherwise the transparent color will appear as black
  2802.         ImageSaveAlpha($this->gdimg_outputtrue);
  2803.         if ($this->is_alpha && phpthumb_functions::gd_version(>= 2{
  2804.  
  2805.             ImageAlphaBlending($this->gdimg_outputfalse);
  2806.             $output_full_alpha phpthumb_functions::ImageColorAllocateAlphaSafe($this->gdimg_output255255255127);
  2807.             ImageFilledRectangle($this->gdimg_output00$this->thumbnail_width$this->thumbnail_height$output_full_alpha);
  2808.  
  2809.         else {
  2810.  
  2811.             $current_transparent_color ImageColorTransparent($this->gdimg_source);
  2812.             if ($this->bg || (@$current_transparent_color >= 0)) {
  2813.  
  2814.                 $this->config_background_hexcolor ($this->bg $this->bg $this->config_background_hexcolor);
  2815.                 if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
  2816.                     return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
  2817.                 }
  2818.                 $background_color phpthumb_functions::ImageHexColorAllocate($this->gdimg_output$this->config_background_hexcolor);
  2819.                 ImageFilledRectangle($this->gdimg_output00$this->thumbnail_width$this->thumbnail_height$background_color);
  2820.  
  2821.             }
  2822.  
  2823.         }
  2824.         $this->DebugMessage('CreateGDoutput() returning canvas "'.$this->thumbnail_width.'x'.$this->thumbnail_height.'"'__FILE____LINE__);
  2825.         return true;
  2826.     }
  2827.  
  2828.     function SetOrientationDependantWidthHeight({
  2829.         $this->DebugMessage('SetOrientationDependantWidthHeight() starting with "'.$this->source_width.'"x"'.$this->source_height.'"'__FILE____LINE__);
  2830.         if ($this->source_height $this->source_width{
  2831.             // portrait
  2832.             $this->w phpthumb_functions::OneOfThese($this->wp$this->w$this->ws$this->wl);
  2833.             $this->h phpthumb_functions::OneOfThese($this->hp$this->h$this->hs$this->hl);
  2834.         elseif ($this->source_height $this->source_width{
  2835.             // landscape
  2836.             $this->w phpthumb_functions::OneOfThese($this->wl$this->w$this->ws$this->wp);
  2837.             $this->h phpthumb_functions::OneOfThese($this->hl$this->h$this->hs$this->hp);
  2838.         else {
  2839.             // square
  2840.             $this->w phpthumb_functions::OneOfThese($this->ws$this->w$this->wl$this->wp);
  2841.             $this->h phpthumb_functions::OneOfThese($this->hs$this->h$this->hl$this->hp);
  2842.         }
  2843.         //$this->w = round($this->w ? $this->w : (($this->h && $this->source_height) ? $this->h * $this->source_width  / $this->source_height : $this->w));
  2844.         //$this->h = round($this->h ? $this->h : (($this->w && $this->source_width)  ? $this->w * $this->source_height / $this->source_width  : $this->h));
  2845.         $this->DebugMessage('SetOrientationDependantWidthHeight() setting w="'.intval($this->w).'", h="'.intval($this->h).'"'__FILE____LINE__);
  2846.         return true;
  2847.     }
  2848.  
  2849.     function ExtractEXIFgetImageSize({
  2850.         $this->DebugMessage('starting ExtractEXIFgetImageSize()'__FILE____LINE__);
  2851.  
  2852.         if (is_resource($this->gdimg_source)) {
  2853.  
  2854.             $this->source_width  ImageSX($this->gdimg_source);
  2855.             $this->source_height ImageSY($this->gdimg_source);
  2856.  
  2857.             $this->SetOrientationDependantWidthHeight();
  2858.  
  2859.         elseif ($this->rawImageData && !$this->sourceFilename{
  2860.  
  2861.             $this->DebugMessage('bypassing EXIF and GetImageSize sections because $this->rawImageData is set and $this->sourceFilename is not set'__FILE____LINE__);
  2862.  
  2863.         }
  2864.  
  2865.         if (is_null($this->getimagesizeinfo)) {
  2866.             $this->getimagesizeinfo @GetImageSize($this->sourceFilename);
  2867.         }
  2868.  
  2869.         if (!empty($this->getimagesizeinfo)) {
  2870.             // great
  2871.             $this->getimagesizeinfo['filesize'@filesize($this->sourceFilename);
  2872.         elseif (!$this->rawImageData{
  2873.             $this->DebugMessage('GetImageSize("'.$this->sourceFilename.'") failed'__FILE____LINE__);
  2874.         }
  2875.  
  2876.         if ($this->config_prefer_imagemagick{
  2877.             if ($this->ImageMagickThumbnailToGD()) {
  2878.                 return true;
  2879.             }
  2880.             $this->DebugMessage('ImageMagickThumbnailToGD() failed'__FILE____LINE__);
  2881.         }
  2882.  
  2883.         $this->source_width  $this->getimagesizeinfo[0];
  2884.         $this->source_height $this->getimagesizeinfo[1];
  2885.  
  2886.         $this->SetOrientationDependantWidthHeight();
  2887.  
  2888.         if (phpthumb_functions::version_compare_replacement(phpversion()'4.2.0''>='&& function_exists('exif_read_data')) {
  2889.             $this->exif_raw_data @exif_read_data($this->sourceFilename0true);
  2890.         }
  2891.         if (function_exists('exif_thumbnail'&& ($this->getimagesizeinfo[2== 2)) {
  2892.             // Extract EXIF info from JPEGs
  2893.  
  2894.             $this->exif_thumbnail_width  '';
  2895.             $this->exif_thumbnail_height '';
  2896.             $this->exif_thumbnail_type   '';
  2897.  
  2898.             // The parameters width, height and imagetype are available since PHP v4.3.0
  2899.             if (phpthumb_functions::version_compare_replacement(phpversion()'4.3.0''>=')) {
  2900.  
  2901.                 $this->exif_thumbnail_data @exif_thumbnail($this->sourceFilename$this->exif_thumbnail_width$this->exif_thumbnail_height$this->exif_thumbnail_type);
  2902.  
  2903.             else {
  2904.  
  2905.                 // older versions of exif_thumbnail output an error message but NOT return false on failure
  2906.                 ob_start();
  2907.                 $this->exif_thumbnail_data exif_thumbnail($this->sourceFilename);
  2908.                 $exit_thumbnail_error ob_get_contents();
  2909.                 ob_end_clean();
  2910.                 if (!$exit_thumbnail_error && $this->exif_thumbnail_data{
  2911.  
  2912.                     if ($gdimg_exif_temp $this->ImageCreateFromStringReplacement($this->exif_thumbnail_datafalse)) {
  2913.                         $this->exif_thumbnail_width  ImageSX($gdimg_exif_temp);
  2914.                         $this->exif_thumbnail_height ImageSY($gdimg_exif_temp);
  2915.                         $this->exif_thumbnail_type   2// (2 == JPEG) before PHP v4.3.0 only JPEG format EXIF thumbnails are returned
  2916.                         unset($gdimg_exif_temp);
  2917.                     else {
  2918.                         return $this->ErrorImage('Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in '.__FILE__.' on line '.__LINE__);
  2919.                     }
  2920.  
  2921.                 }
  2922.  
  2923.             }
  2924.  
  2925.         elseif (!function_exists('exif_thumbnail')) {
  2926.  
  2927.             $this->DebugMessage('exif_thumbnail() does not exist, cannot extract EXIF thumbnail'__FILE____LINE__);
  2928.             return false;
  2929.  
  2930.         }
  2931.  
  2932.         $this->DebugMessage('EXIF thumbnail extraction: (size='.strlen($this->exif_thumbnail_data).'; type="'.$this->exif_thumbnail_type.'"; '.intval($this->exif_thumbnail_width).'x'.intval($this->exif_thumbnail_height).')'__FILE____LINE__);
  2933.  
  2934.         // see if EXIF thumbnail can be used directly with no processing
  2935.         if ($this->config_use_exif_thumbnail_for_speed && $this->exif_thumbnail_data{
  2936.             while (true{
  2937.                 if (!$this->xto{
  2938.                     $source_ar $this->source_width $this->source_height;
  2939.                     $exif_ar $this->exif_thumbnail_width $this->exif_thumbnail_height;
  2940.                     if (number_format($source_ar2!= number_format($exif_ar2)) {
  2941.                         $this->DebugMessage('not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.' != '.$exif_ar.')'__FILE____LINE__);
  2942.                         break;
  2943.                     }
  2944.                     if ($this->w && ($this->w != $this->exif_thumbnail_width)) {
  2945.                         $this->DebugMessage('not using EXIF thumbnail because $this->w != $this->exif_thumbnail_width ('.$this->w.' != '.$this->exif_thumbnail_width.')'__FILE____LINE__);
  2946.                         break;
  2947.                     }
  2948.                     if ($this->h && ($this->h != $this->exif_thumbnail_height)) {
  2949.                         $this->DebugMessage('not using EXIF thumbnail because $this->h != $this->exif_thumbnail_height ('.$this->h.' != '.$this->exif_thumbnail_height.')'__FILE____LINE__);
  2950.                         break;
  2951.                     }
  2952.                     $CannotBeSetParameters array('sx''sy''sh''sw''far''bg''bc''fltr''phpThumbDebug');
  2953.                     foreach ($CannotBeSetParameters as $parameter{
  2954.                         if ($this->$parameter{
  2955.                             break 2;
  2956.                         }
  2957.                     }
  2958.                 }
  2959.  
  2960.                 $this->DebugMessage('setting $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data)'__FILE____LINE__);
  2961.                 $this->gdimg_source $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data);
  2962.                 $this->source_width  ImageSX($this->gdimg_source);
  2963.                 $this->source_height ImageSY($this->gdimg_source);
  2964.                 return true;
  2965.             }
  2966.         }
  2967.  
  2968.         if (($this->config_max_source_pixels 0&& (($this->source_width $this->source_height$this->config_max_source_pixels)) {
  2969.  
  2970.             // Source image is larger than would fit in available PHP memory.
  2971.             // If ImageMagick is installed, use it to generate the thumbnail.
  2972.             // Else, if an EXIF thumbnail is available, use that as the source image.
  2973.             // Otherwise, no choice but to fail with an error message
  2974.             $this->DebugMessage('image is '.$this->source_width.'x'.$this->source_height.' and therefore contains more pixels ('.($this->source_width $this->source_height).') than $this->config_max_source_pixels setting ('.$this->config_max_source_pixels.')'__FILE____LINE__);
  2975.             if (!$this->config_prefer_imagemagick && $this->ImageMagickThumbnailToGD()) {
  2976.                 // excellent, we have a thumbnailed source image
  2977.                 return true;
  2978.             }
  2979.  
  2980.         }
  2981.         return true;
  2982.     }
  2983.  
  2984.  
  2985.     function SetCacheFilename({
  2986.         if (!is_null($this->cache_filename)) {
  2987.             $this->DebugMessage('$this->cache_filename already set, skipping SetCacheFilename()'__FILE____LINE__);
  2988.             return true;
  2989.         }
  2990.         $this->setOutputFormat();
  2991.         $this->setCacheDirectory();
  2992.         if (!$this->config_cache_directory{
  2993.             $this->DebugMessage('SetCacheFilename() failed because $this->config_cache_directory is empty'__FILE____LINE__);
  2994.             return false;
  2995.         }
  2996.  
  2997.         if (!$this->sourceFilename && !$this->rawImageData && $this->src{
  2998.             $this->sourceFilename $this->ResolveFilenameToAbsolute($this->src);
  2999.         }
  3000.  
  3001.         if ($this->config_cache_default_only_suffix && $this->sourceFilename{
  3002.             // simplified cache filenames:
  3003.             // only use default parameters in phpThumb.config.php
  3004.             // substitute source filename into * in $this->config_cache_default_only_suffix
  3005.             // (eg: '*_thumb' becomes 'picture_thumb.jpg')
  3006.             if (strpos($this->config_cache_default_only_suffix'*'=== false{
  3007.                 $this->DebugMessage('aborting simplified caching filename because no * in "'.$this->config_cache_default_only_suffix.'"'__FILE____LINE__);
  3008.             else {
  3009.                 eregi('(.+)(\.[a-z0-9]+)?$'basename($this->sourceFilename)$matches);
  3010.                 $this->cache_filename $this->config_cache_directory.DIRECTORY_SEPARATOR.rawurlencode(str_replace('*'@$matches[1]$this->config_cache_default_only_suffix)).'.'.strtolower($this->thumbnailFormat);
  3011.                 return true;
  3012.             }
  3013.         }
  3014.  
  3015.         $this->cache_filename '';
  3016.         $broad_directory_name '';
  3017.         if ($this->new{
  3018.             $broad_directory_name strtolower(md5($this->new));
  3019.             $this->cache_filename .= '_new'.$broad_directory_name;
  3020.         elseif ($this->md5s{
  3021.             // source image MD5 hash provided
  3022.             $this->DebugMessage('SetCacheFilename() _raw set from $this->md5s = "'.$this->md5s.'"'__FILE____LINE__);
  3023.             $broad_directory_name $this->md5s;
  3024.             $this->cache_filename .= '_raw'.$this->md5s;
  3025.         elseif (!$this->src && $this->rawImageData{
  3026.             $this->DebugMessage('SetCacheFilename() _raw set from md5($this->rawImageData) = "'.md5($this->rawImageData).'"'__FILE____LINE__);
  3027.             $broad_directory_name strtolower(md5($this->rawImageData));
  3028.             $this->cache_filename .= '_raw'.$broad_directory_name;
  3029.         else {
  3030.             $this->DebugMessage('SetCacheFilename() _src set from md5($this->sourceFilename) "'.$this->sourceFilename.'" = "'.md5($this->sourceFilename).'"'__FILE____LINE__);
  3031.             $broad_directory_name strtolower(md5($this->sourceFilename));
  3032.             $this->cache_filename .= '_src'.$broad_directory_name;
  3033.         }
  3034.         if (@$_SERVER['HTTP_REFERER'&& $this->config_nooffsitelink_enabled{
  3035.             $parsed_url1 @phpthumb_functions::ParseURLbetter(@$_SERVER['HTTP_REFERER']);
  3036.             $parsed_url2 @phpthumb_functions::ParseURLbetter('http://'.@$_SERVER['HTTP_HOST']);
  3037.             if (@$parsed_url1['host'&& @$parsed_url2['host'&& ($parsed_url1['host'!= $parsed_url2['host'])) {
  3038.                 // include "_offsite" only if nooffsitelink_enabled and if referrer doesn't match the domain of the current server
  3039.                 $this->cache_filename .= '_offsite';
  3040.             }
  3041.         }
  3042.  
  3043.         $ParametersString '';
  3044.         if ($this->fltr && is_array($this->fltr)) {
  3045.             $ParametersString .= '_fltr'.implode('_fltr'$this->fltr);
  3046.         }
  3047.         $FilenameParameters1 array('ar''bg''bc''far''sx''sy''sw''sh''zc');
  3048.         foreach ($FilenameParameters1 as $key{
  3049.             if ($this->$key{
  3050.                 $ParametersString .= '_'.$key.$this->$key;
  3051.             }
  3052.         }
  3053.         $FilenameParameters2 array('h''w''wl''wp''ws''hp''hs''xto''ra''iar''aoe''maxb''sfn''dpi');
  3054.         foreach ($FilenameParameters2 as $key{
  3055.             if ($this->$key{
  3056.                 $ParametersString .= '_'.$key.intval($this->$key);
  3057.             }
  3058.         }
  3059.         if ($this->thumbnailFormat == 'jpeg'{
  3060.             // only JPEG output has variable quality option
  3061.             $ParametersString .= '_q'.intval($this->thumbnailQuality);
  3062.         }
  3063.         $this->DebugMessage('SetCacheFilename() _par set from md5('.$ParametersString.')'__FILE____LINE__);
  3064.         $this->cache_filename .= '_par'.strtolower(md5($ParametersString));
  3065.  
  3066.         if ($this->md5s{
  3067.             // source image MD5 hash provided
  3068.             // do not source image modification date --
  3069.             // cached image will be used even if file was modified or removed
  3070.         elseif (!$this->config_cache_source_filemtime_ignore_remote && eregi('^(f|ht)tps?\://'$this->src)) {
  3071.             $this->cache_filename .= '_dat'.intval(phpthumb_functions::filedate_remote($this->src));
  3072.         elseif (!$this->config_cache_source_filemtime_ignore_local && $this->src && !$this->rawImageData{
  3073.             $this->cache_filename .= '_dat'.intval(@filemtime($this->sourceFilename));
  3074.         }
  3075.  
  3076.         $this->cache_filename .= '.'.strtolower($this->thumbnailFormat);
  3077.         $broad_directories '';
  3078.         for ($i 0$i $this->config_cache_directory_depth$i++{
  3079.             $broad_directories .= DIRECTORY_SEPARATOR.substr($broad_directory_name0$i 1);
  3080.         }
  3081.  
  3082.         $this->cache_filename $this->config_cache_directory.$broad_directories.DIRECTORY_SEPARATOR.$this->config_cache_prefix.rawurlencode($this->cache_filename);
  3083.         return true;
  3084.     }
  3085.  
  3086.  
  3087.     function SourceImageIsTooLarge($width$height{
  3088.         if (!$this->config_max_source_pixels{
  3089.             return false;
  3090.         }
  3091.         if (function_exists('memory_get_usage')) {
  3092.             $available_memory max(intval(ini_get('memory_limit'))intval(get_cfg_var('memory_limit'))) 1048576;
  3093.             $available_memory -= memory_get_usage();
  3094.             return (bool) (($width $height 5$available_memory);
  3095.         }
  3096.         return (bool) (($width $height$this->config_max_source_pixels);
  3097.     }
  3098.  
  3099.     function ImageCreateFromFilename($filename{
  3100.         // try to create GD image source directly via GD, if possible,
  3101.         // rather than buffering to memory and creating with ImageCreateFromString
  3102.         $ImageCreateWasAttempted false;
  3103.         $gd_image false;
  3104.  
  3105.         $this->DebugMessage('starting ImageCreateFromFilename('.$filename.')'__FILE____LINE__);
  3106.         if ($filename && ($getimagesizeinfo @GetImageSize($filename))) {
  3107.             if (!$this->SourceImageIsTooLarge($getimagesizeinfo[0]$getimagesizeinfo[1])) {
  3108.                 $ImageCreateFromFunction array(
  3109.                     1  => 'ImageCreateFromGIF',
  3110.                     2  => 'ImageCreateFromJPEG',
  3111.                     3  => 'ImageCreateFromPNG',
  3112.                     15 => 'ImageCreateFromWBMP',
  3113.                 );
  3114.                 $this->DebugMessage('ImageCreateFromFilename found ($getimagesizeinfo[2]=='.@$getimagesizeinfo[2].')'__FILE____LINE__);
  3115.                 switch (@$getimagesizeinfo[2]{
  3116.                     case 1:  // GIF
  3117.                     case 2:  // JPEG
  3118.                     case 3:  // PNG
  3119.                     case 15// WBMP
  3120.                         $ImageCreateFromFunctionName $ImageCreateFromFunction[$getimagesizeinfo[2]];
  3121.                         if (function_exists($ImageCreateFromFunctionName)) {
  3122.                             $this->DebugMessage('Calling '.$ImageCreateFromFunctionName.'('.$filename.')'__FILE____LINE__);
  3123.                             $ImageCreateWasAttempted true;
  3124.                             $gd_image $ImageCreateFromFunctionName($filename);
  3125.                         else {
  3126.                             $this->DebugMessage('NOT calling '.$ImageCreateFromFunctionName.'('.$filename.') because !function_exists('.$ImageCreateFromFunctionName.')'__FILE____LINE__);
  3127.                         }
  3128.                         break;
  3129.  
  3130.                     case 4:  // SWF
  3131.                     case 5:  // PSD
  3132.                     case 6:  // BMP
  3133.                     case 7:  // TIFF (LE)
  3134.                     case 8:  // TIFF (BE)
  3135.                     case 9:  // JPC
  3136.                     case 10// JP2
  3137.                     case 11// JPX
  3138.                     case 12// JB2
  3139.                     case 13// SWC
  3140.                     case 14// IFF
  3141.                     case 16// XBM
  3142.                         $this->DebugMessage('No built-in image creation function for image type "'.@$getimagesizeinfo[2].'" ($getimagesizeinfo[2])'__FILE____LINE__);
  3143.                         break;
  3144.  
  3145.                     default:
  3146.                         $this->DebugMessage('Unknown value for $getimagesizeinfo[2]: "'.@$getimagesizeinfo[2].'"'__FILE____LINE__);
  3147.                         break;
  3148.                 }
  3149.             else {
  3150.                 $this->DebugMessage('image is '.$getimagesizeinfo[0].'x'.$getimagesizeinfo[1].' and therefore contains more pixels ('.($getimagesizeinfo[0$getimagesizeinfo[1]).') than $this->config_max_source_pixels setting ('.$this->config_max_source_pixels.')'__FILE____LINE__);
  3151.                 return false;
  3152.             }
  3153.         else {
  3154.             $this->DebugMessage('empty $filename or GetImageSize('.$filename.') failed'__FILE____LINE__);
  3155.         }
  3156.  
  3157.         if (!$gd_image{
  3158.             // cannot create from filename, attempt to create source image with ImageCreateFromString, if possible
  3159.             if ($ImageCreateWasAttempted{
  3160.                 $this->DebugMessage(@$ImageCreateFromFunctionName.'() was attempted but FAILED'__FILE____LINE__);
  3161.             }
  3162.             $this->DebugMessage('Populating $rawimagedata'__FILE____LINE__);
  3163.             $rawimagedata '';
  3164.             if ($fp @fopen($filename'rb')) {
  3165.                 $filesize filesize($filename);
  3166.                 $blocksize 8192;
  3167.                 $blockreads ceil($filesize $blocksize);
  3168.                 for ($i 0$i $blockreads$i++{
  3169.                     $rawimagedata .= fread($fp$blocksize);
  3170.                 }
  3171.                 fclose($fp);
  3172.             else {
  3173.                 $this->DebugMessage('cannot fopen('.$filename.')'__FILE____LINE__);
  3174.             }
  3175.             if ($rawimagedata{
  3176.                 $this->DebugMessage('attempting ImageCreateFromStringReplacement($rawimagedata ('.strlen($rawimagedata).' bytes), true)'__FILE____LINE__);
  3177.                 $gd_image $this->ImageCreateFromStringReplacement($rawimagedatatrue);
  3178.             }
  3179.         }
  3180.         return $gd_image;
  3181.     }
  3182.  
  3183.     function SourceImageToGD({
  3184.         if (is_resource($this->gdimg_source)) {
  3185.             $this->source_width  ImageSX($this->gdimg_source);
  3186.             $this->source_height ImageSY($this->gdimg_source);
  3187.             $this->DebugMessage('skipping SourceImageToGD() because $this->gdimg_source is already a resource ('.$this->source_width.'x'.$this->source_height.')'__FILE____LINE__);
  3188.             return true;
  3189.         }
  3190.         $this->DebugMessage('starting SourceImageToGD()'__FILE____LINE__);
  3191.  
  3192.         if ($this->ImageMagickThumbnailToGD()) {
  3193.  
  3194.             // excellent, we have a thumbnailed source image
  3195.             $this->DebugMessage('ImageMagickThumbnailToGD() succeeded'__FILE____LINE__);
  3196.  
  3197.         elseif (!$this->gdimg_source && $this->rawImageData{
  3198.  
  3199.             if ($this->md5s && ($this->md5s != md5($this->rawImageData))) {
  3200.                 return $this->ErrorImage('$this->md5s != md5($this->rawImageData)'."\n".'"'.$this->md5s.'" != '."\n".'"'.md5($this->rawImageData).'"');
  3201.             }
  3202.             $this->gdimg_source $this->ImageCreateFromStringReplacement($this->rawImageData);
  3203.             if (!$this->gdimg_source{
  3204.                 if (substr($this->rawImageData02=== 'BM'{
  3205.                     $this->getimagesizeinfo[26// BMP
  3206.                 elseif (substr($this->rawImageData04=== 'II'."\x2A\x00"{
  3207.                     $this->getimagesizeinfo[27// TIFF (littlendian)
  3208.                 elseif (substr($this->rawImageData04=== 'MM'."\x00\x2A"{
  3209.                     $this->getimagesizeinfo[28// TIFF (bigendian)
  3210.                 }
  3211.                 $this->DebugMessage('SourceImageToGD.ImageCreateFromStringReplacement() failed with unknown image type "'.substr($this->rawImageData04).'" ('.phpthumb_functions::HexCharDisplay(substr($this->rawImageData04)).')'__FILE____LINE__);
  3212. //                return $this->ErrorImage('Unknown image type identified by "'.substr($this->rawImageData, 0, 4).'" ('.phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)).') in SourceImageToGD()['.__LINE__.']');
  3213.             }
  3214.  
  3215.         elseif (!$this->gdimg_source && $this->sourceFilename{
  3216.  
  3217.             if ($this->md5s && ($this->md5s != phpthumb_functions::md5_file_safe($this->sourceFilename))) {
  3218.                 return $this->ErrorImage('$this->md5s != md5(sourceFilename)'."\n".'"'.$this->md5s.'" != '."\n".'"'.phpthumb_functions::md5_file_safe($this->sourceFilename).'"');
  3219.             }
  3220.             switch (@$this->getimagesizeinfo[2]{
  3221.                 case 1:
  3222.                 case 3:
  3223.                     // GIF or PNG input file may have transparency
  3224.                     $this->is_alpha true;
  3225.                     break;
  3226.             }
  3227.             if (!$this->SourceImageIsTooLarge($this->source_width$this->source_height)) {
  3228.                 $this->gdimg_source $this->ImageCreateFromFilename($this->sourceFilename);
  3229.             }
  3230.  
  3231.         }
  3232.  
  3233.         while (true{
  3234.             if ($this->gdimg_source{
  3235.                 $this->DebugMessage('Not using EXIF thumbnail data because $this->gdimg_source is already set'__FILE____LINE__);
  3236.                 break;
  3237.             }
  3238.             if (!$this->exif_thumbnail_data{
  3239.                 $this->DebugMessage('Not using EXIF thumbnail data because $this->exif_thumbnail_data is empty'__FILE____LINE__);
  3240.                 break;
  3241.             }
  3242.             if (ini_get('safe_mode')) {
  3243.                 if (!$this->SourceImageIsTooLarge($this->source_width$this->source_height)) {
  3244.                     $this->DebugMessage('Using EXIF thumbnail data because source image too large and safe_mode enabled'__FILE____LINE__);
  3245.                     $this->aoe true;
  3246.                 else {
  3247.                     break;
  3248.                 }
  3249.             else {
  3250.                 if (!$this->config_use_exif_thumbnail_for_speed{
  3251.                     $this->DebugMessage('Not using EXIF thumbnail data because $this->config_use_exif_thumbnail_for_speed is FALSE'__FILE____LINE__);
  3252.                     break;
  3253.                 }
  3254.                 if (($this->thumbnailCropX != 0|| ($this->thumbnailCropY != 0)) {
  3255.                     $this->DebugMessage('Not using EXIF thumbnail data because source cropping is enabled ('.$this->thumbnailCropX.','.$this->thumbnailCropY.')'__FILE____LINE__);
  3256.                     break;
  3257.                 }
  3258.                 if (($this->w $this->exif_thumbnail_width|| ($this->h $this->exif_thumbnail_height)) {
  3259.                     $this->DebugMessage('Not using EXIF thumbnail data because EXIF thumbnail is too small ('.$this->exif_thumbnail_width.'x'.$this->exif_thumbnail_height.' vs '.$this->w.'x'.$this->h.')'__FILE____LINE__);
  3260.                     break;
  3261.                 }
  3262.                 $source_ar $this->source_width $this->source_height;
  3263.                 $exif_ar   $this->exif_thumbnail_width $this->exif_thumbnail_height;
  3264.                 if (number_format($source_ar2!= number_format($exif_ar2)) {
  3265.                     $this->DebugMessage('not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.' != '.$exif_ar.')'__FILE____LINE__);
  3266.                     break;
  3267.                 }
  3268.             }
  3269.  
  3270.             // EXIF thumbnail exists, and is equal to or larger than destination thumbnail, and will be use as source image
  3271.             $this->DebugMessage('Trying to use EXIF thumbnail as source image'__FILE____LINE__);
  3272.  
  3273.             if ($gdimg_exif_temp $this->ImageCreateFromStringReplacement($this->exif_thumbnail_datafalse)) {
  3274.  
  3275.                 $this->DebugMessage('Successfully using EXIF thumbnail as source image'__FILE____LINE__);
  3276.                 $this->gdimg_source   $gdimg_exif_temp;
  3277.                 $this->source_width   $this->exif_thumbnail_width;
  3278.                 $this->source_height  $this->exif_thumbnail_height;
  3279.                 $this->thumbnailCropW $this->source_width;
  3280.                 $this->thumbnailCropH $this->source_height;
  3281.                 return true;
  3282.  
  3283.             else {
  3284.                 $this->DebugMessage('$this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false) failed'__FILE____LINE__);
  3285.             }
  3286.  
  3287.             break;
  3288.         }
  3289.  
  3290.         if (!$this->gdimg_source{
  3291.             $this->DebugMessage('$this->gdimg_source is still empty'__FILE____LINE__);
  3292.  
  3293.             $this->DebugMessage('ImageMagickThumbnailToGD() failed'__FILE____LINE__);
  3294.  
  3295.             $imageHeader '';
  3296.             $gd_info gd_info();
  3297.             $GDreadSupport false;
  3298.             switch (@$this->getimagesizeinfo[2]{
  3299.                 case 1:
  3300.                     $imageHeader 'Content-Type: image/gif';
  3301.                     $GDreadSupport = (bool) @$gd_info['GIF Read Support'];
  3302.                     break;
  3303.                 case 2:
  3304.                     $imageHeader 'Content-Type: image/jpeg';
  3305.                     $GDreadSupport = (bool) @$gd_info['JPG Support'];
  3306.                     break;
  3307.                 case 3:
  3308.                     $imageHeader 'Content-Type: image/png';
  3309.                     $GDreadSupport = (bool) @$gd_info['PNG Support'];
  3310.                     break;
  3311.             }
  3312.             if ($imageHeader{
  3313.                 // cannot create image for whatever reason (maybe ImageCreateFromJPEG et al are not available?)
  3314.                 // and ImageMagick is not available either, no choice but to output original (not resized/modified) data and exit
  3315.                 if ($this->config_error_die_on_source_failure{
  3316.                     $errormessages array();
  3317.                     $errormessages['All attempts to create GD image source failed.';
  3318.                     if ($this->fatalerror{
  3319.                         $errormessages[$this->fatalerror;
  3320.                     }
  3321.                     if (ini_get('safe_mode')) {
  3322.                         $errormessages['Safe Mode enabled, therefore ImageMagick is unavailable. (disable Safe Mode if possible)';
  3323.                     elseif (!$this->ImageMagickVersion()) {
  3324.                         $errormessages['ImageMagick is not installed (it is highly recommended that you install it).';
  3325.                     }
  3326.                     if ($this->SourceImageIsTooLarge($this->getimagesizeinfo[0]$this->getimagesizeinfo[1])) {
  3327.                         $memory_get_usage (function_exists('memory_get_usage'memory_get_usage(0);
  3328.                         $errormessages['Source image is too large ('.$this->getimagesizeinfo[0].'x'.$this->getimagesizeinfo[1].' = '.number_format($this->getimagesizeinfo[0$this->getimagesizeinfo[110000001).'Mpx, max='.number_format($this->config_max_source_pixels 10000001).'Mpx) for GD creation (either install ImageMagick or increase PHP memory_limit to at least '.ceil(($memory_get_usage ($this->getimagesizeinfo[0$this->getimagesizeinfo[1])) 1000000).'M).';
  3329.                     elseif (!$GDreadSupport{
  3330.                         $errormessages['GD does not have read support for "'.$imageHeader.'".';
  3331.                     else {
  3332.                         $errormessages['Source image probably corrupt.';
  3333.                     }
  3334.                     $this->ErrorImage(implode("\n"$errormessages));
  3335.  
  3336.                 else {
  3337.                     $this->DebugMessage('All attempts to create GD image source failed ('.(ini_get('safe_mode''Safe Mode enabled, ImageMagick unavailable and source image probably too large for GD'($GDreadSupport 'source image probably corrupt' 'GD does not have read support for "'.$imageHeader.'"')).'), cannot generate thumbnail');
  3338.                     //$this->DebugMessage('All attempts to create GD image source failed ('.($GDreadSupport ? 'source image probably corrupt' : 'GD does not have read support for "'.$imageHeader.'"').'), outputing raw image', __FILE__, __LINE__);
  3339.                     //if (!$this->phpThumbDebug) {
  3340.                     //    header($imageHeader);
  3341.                     //    echo $this->rawImageData;
  3342.                     //    exit;
  3343.                     //}
  3344.                     return false;
  3345.                 }
  3346.             }
  3347.  
  3348.             //switch (substr($this->rawImageData, 0, 2)) {
  3349.             //    case 'BM':
  3350.             switch (@$this->getimagesizeinfo[2]{
  3351.                 case 6:
  3352.                     ob_start();
  3353.                     if (!@include_once(dirname(__FILE__).'/phpthumb.bmp.php')) {
  3354.                         ob_end_clean();
  3355.                         return $this->ErrorImage('include_once('.dirname(__FILE__).'/phpthumb.bmp.php) failed');
  3356.                     }
  3357.                     ob_end_clean();
  3358.                     if ($fp @fopen($this->sourceFilename'rb')) {
  3359.                         $this->rawImageData '';
  3360.                         while (!feof($fp)) {
  3361.                             $this->rawImageData .= fread($fp32768);
  3362.                         }
  3363.                         fclose($fp);
  3364.                     }
  3365.                     $phpthumb_bmp new phpthumb_bmp();
  3366.                     $this->gdimg_source $phpthumb_bmp->phpthumb_bmp2gd($this->rawImageData(phpthumb_functions::gd_version(>= 2.0));
  3367.                     unset($phpthumb_bmp);
  3368.                     if ($this->gdimg_source{
  3369.                         $this->DebugMessage('$phpthumb_bmp->phpthumb_bmp2gd() succeeded'__FILE____LINE__);
  3370.                     else {
  3371.                         return $this->ErrorImage($this->ImageMagickVersion('ImageMagick failed on BMP source conversion' 'phpthumb_bmp2gd() failed');
  3372.                     }
  3373.                     break;
  3374.             //}
  3375.             //switch (substr($this->rawImageData, 0, 4)) {
  3376.             //    case 'II'."\x2A\x00":
  3377.             //    case 'MM'."\x00\x2A":
  3378.                 case 7:
  3379.                 case 8:
  3380.                     return $this->ErrorImage($this->ImageMagickVersion('ImageMagick failed on TIFF source conversion' 'ImageMagick is unavailable and phpThumb() does not support TIFF source images without it');
  3381.                     break;
  3382.  
  3383.                 //case "\xD7\xCD\xC6\x9A":
  3384.                 //    return $this->ErrorImage($this->ImageMagickVersion() ? 'ImageMagick failed on WMF source conversion' : 'ImageMagick is unavailable and phpThumb() does not support WMF source images without it');
  3385.                 //    break;
  3386.             }
  3387.  
  3388.             if (!$this->gdimg_source{
  3389.                 $HeaderFourBytes '';
  3390.                 if ($fp @fopen($this->sourceFilename'rb')) {
  3391.                     $HeaderFourBytes fread($fp4);
  3392.                     fclose($fp);
  3393.                 }
  3394.                 if ($HeaderFourBytes == "\xD7\xCD\xC6\x9A"// WMF
  3395.                     return $this->ErrorImage($this->ImageMagickVersion('ImageMagick failed on WMF source conversion' 'ImageMagick is unavailable and phpThumb() does not support WMF source images without it');
  3396.                 elseif ($HeaderFourBytes == '%PDF'// "%PDF"
  3397.                     return $this->ErrorImage($this->ImageMagickVersion('ImageMagick and GhostScript are both required for PDF source images; GhostScript may not be properly configured' 'ImageMagick and/or GhostScript are unavailable and phpThumb() does not support PDF source images without them');
  3398.                 elseif (substr($HeaderFourBytes03== "\xFF\xD8\xFF"// JPEG
  3399.                     return $this->ErrorImage('Image is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
  3400.                 elseif ($HeaderFourBytes == '%PNG'// "%PNG"
  3401.                     return $this->ErrorImage('Image is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
  3402.                 elseif (substr($HeaderFourBytes03== 'GIF'// GIF
  3403.                     return $this->ErrorImage('Image is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
  3404.                 }
  3405.                 return $this->ErrorImage('Unknown image type identified by "'.substr($HeaderFourBytes04).'" ('.phpthumb_functions::HexCharDisplay(substr($HeaderFourBytes04)).') in SourceImageToGD()['.__LINE__.']');
  3406.  
  3407.             }
  3408.         }
  3409.  
  3410.         if (!$this->gdimg_source{
  3411.             if ($gdimg_exif_temp $this->ImageCreateFromStringReplacement($this->exif_thumbnail_datafalse)) {
  3412.                 $this->DebugMessage('All other attempts failed, but successfully using EXIF thumbnail as source image'__FILE____LINE__);
  3413.                 $this->gdimg_source   $gdimg_exif_temp;
  3414.                 // override allow-enlarging setting if EXIF thumbnail is the only source available
  3415.                 // otherwise thumbnails larger than the EXIF thumbnail will be created at EXIF size
  3416.                 $this->aoe true;
  3417.                 return true;
  3418.             }
  3419.             return false;
  3420.         }
  3421.  
  3422.         $this->source_width  ImageSX($this->gdimg_source);
  3423.         $this->source_height ImageSY($this->gdimg_source);
  3424.         return true;
  3425.     }
  3426.  
  3427.  
  3428.     function phpThumbDebugVarDump($var{
  3429.         if (is_null($var)) {
  3430.             return 'NULL';
  3431.         elseif (is_bool($var)) {
  3432.             return ($var 'TRUE' 'FALSE');
  3433.         elseif (is_string($var)) {
  3434.             return 'string('.strlen($var).')'.str_repeat(' 'max(0strlen(strlen($var)))).' "'.$var.'"';
  3435.         elseif (is_int($var)) {
  3436.             return 'integer     '.$var;
  3437.         elseif (is_float($var)) {
  3438.             return 'float       '.$var;
  3439.         elseif (is_array($var)) {
  3440.             ob_start();
  3441.             var_dump($var);
  3442.             $vardumpoutput ob_get_contents();
  3443.             ob_end_clean();
  3444.             return strtr($vardumpoutput"\n\r\t"'   ');
  3445.         }
  3446.         return gettype($var);
  3447.     }
  3448.  
  3449.     function phpThumbDebug($level=''{
  3450.         if ($level && ($this->phpThumbDebug !== $level)) {
  3451.             return true;
  3452.         }
  3453.         if ($this->config_disable_debug{
  3454.             return $this->ErrorImage('phpThumbDebug disabled');
  3455.         }
  3456.  
  3457.         $FunctionsExistance  array('exif_thumbnail''gd_info''image_type_to_mime_type''ImageCopyResampled''ImageCopyResized''ImageCreate''ImageCreateFromString''ImageCreateTrueColor''ImageIsTrueColor''ImageRotate''ImageTypes''version_compare''ImageCreateFromGIF''ImageCreateFromJPEG''ImageCreateFromPNG''ImageCreateFromWBMP''ImageCreateFromXBM''ImageCreateFromXPM''ImageCreateFromString''ImageCreateFromGD''ImageCreateFromGD2''ImageCreateFromGD2Part''ImageJPEG''ImageGIF''ImagePNG''ImageWBMP');
  3458.         $ParameterNames      array('src''new''w''h''f''q''sx''sy''sw''sh''far''bg''bc''file''goto''err''xto''ra''ar''aoe''iar''maxb');
  3459.         $ConfigVariableNames array('document_root''temp_directory''output_format''output_maxwidth''output_maxheight''error_message_image_default''error_bgcolor''error_textcolor''error_fontsize''error_die_on_error''error_silent_die_on_error''error_die_on_source_failure''nohotlink_enabled''nohotlink_valid_domains''nohotlink_erase_image''nohotlink_text_message''nooffsitelink_enabled''nooffsitelink_valid_domains''nooffsitelink_require_refer''nooffsitelink_erase_image''nooffsitelink_text_message''high_security_enabled''allow_src_above_docroot''allow_src_above_phpthumb''allow_parameter_file''allow_parameter_goto''max_source_pixels''use_exif_thumbnail_for_speed''border_hexcolor''background_hexcolor''ttf_directory''disable_pathinfo_parsing''disable_imagecopyresampled');
  3460.         $OtherVariableNames  array('phpThumbDebug''thumbnailQuality''thumbnailFormat''gdimg_output''gdimg_source''sourceFilename''source_width''source_height''thumbnailCropX''thumbnailCropY''thumbnailCropW''thumbnailCropH''exif_thumbnail_width''exif_thumbnail_height''exif_thumbnail_type''thumbnail_width''thumbnail_height''thumbnail_image_width''thumbnail_image_height');
  3461.  
  3462.         $DebugOutput array();
  3463.         $DebugOutput['phpThumb() version          = '.$this->phpthumb_version;
  3464.         $DebugOutput['phpversion()                = '.@phpversion();
  3465.         $DebugOutput['PHP_OS                      = '.PHP_OS;
  3466.         $DebugOutput['__FILE__                    = '.__FILE__;
  3467.         $DebugOutput['realpath(.)                 = '.@realpath('.');
  3468.         $DebugOutput['$_SERVER[PHP_SELF]          = '.@$_SERVER['PHP_SELF'];
  3469.         $DebugOutput['$_SERVER[HOST_NAME]         = '.@$_SERVER['HOST_NAME'];
  3470.         $DebugOutput['$_SERVER[HTTP_REFERER]      = '.@$_SERVER['HTTP_REFERER'];
  3471.         $DebugOutput['$_SERVER[QUERY_STRING]      = '.@$_SERVER['QUERY_STRING'];
  3472.         $DebugOutput['$_SERVER[PATH_INFO]         = '.@$_SERVER['PATH_INFO'];
  3473.         $DebugOutput['$_SERVER[DOCUMENT_ROOT]     = '.@$_SERVER['DOCUMENT_ROOT'];
  3474.         $DebugOutput['getenv(DOCUMENT_ROOT)       = '.@getenv('DOCUMENT_ROOT');
  3475.         $DebugOutput['';
  3476.  
  3477.         $DebugOutput['get_magic_quotes_gpc()         = '.$this->phpThumbDebugVarDump(@get_magic_quotes_gpc());
  3478.         $DebugOutput['get_magic_quotes_runtime()     = '.$this->phpThumbDebugVarDump(@get_magic_quotes_runtime());
  3479.         $DebugOutput['error_reporting()              = '.$this->phpThumbDebugVarDump(error_reporting());
  3480.         $DebugOutput['ini_get(error_reporting)       = '.$this->phpThumbDebugVarDump(@ini_get('error_reporting'));
  3481.         $DebugOutput['ini_get(display_errors)        = '.$this->phpThumbDebugVarDump(@ini_get('display_errors'));
  3482.         $DebugOutput['ini_get(allow_url_fopen)       = '.$this->phpThumbDebugVarDump(@ini_get('allow_url_fopen'));
  3483.         $DebugOutput['ini_get(disable_functions)     = '.$this->phpThumbDebugVarDump(@ini_get('disable_functions'));
  3484.         $DebugOutput['get_cfg_var(disable_functions) = '.$this->phpThumbDebugVarDump(@get_cfg_var('disable_functions'));
  3485.         $DebugOutput['ini_get(safe_mode)             = '.$this->phpThumbDebugVarDump(@ini_get('safe_mode'));
  3486.         $DebugOutput['ini_get(open_basedir)          = '.$this->phpThumbDebugVarDump(@ini_get('open_basedir'));
  3487.         $DebugOutput['ini_get(max_execution_time)    = '.$this->phpThumbDebugVarDump(@ini_get('max_execution_time'));
  3488.         $DebugOutput['ini_get(memory_limit)          = '.$this->phpThumbDebugVarDump(@ini_get('memory_limit'));
  3489.         $DebugOutput['get_cfg_var(memory_limit)      = '.$this->phpThumbDebugVarDump(@get_cfg_var('memory_limit'));
  3490.         $DebugOutput['memory_get_usage()             = '.(function_exists('memory_get_usage'$this->phpThumbDebugVarDump(@memory_get_usage()) 'n/a');
  3491.         $DebugOutput['';
  3492.  
  3493.         $DebugOutput['$this->config_prefer_imagemagick            = '.$this->phpThumbDebugVarDump($this->config_prefer_imagemagick);
  3494.         $DebugOutput['$this->config_imagemagick_path              = '.$this->phpThumbDebugVarDump($this->config_imagemagick_path);
  3495.         $DebugOutput['$this->ImageMagickWhichConvert()            = '.$this->ImageMagickWhichConvert();
  3496.         $IMpathUsed ($this->config_imagemagick_path $this->config_imagemagick_path $this->ImageMagickWhichConvert());
  3497.         $DebugOutput['[actual ImageMagick path used]              = '.$this->phpThumbDebugVarDump($IMpathUsed);
  3498.         $DebugOutput['file_exists([actual ImageMagick path used]) = '.$this->phpThumbDebugVarDump(@file_exists($IMpathUsed));
  3499.         $DebugOutput['ImageMagickVersion(false)                   = '.$this->ImageMagickVersion(false);
  3500.         $DebugOutput['ImageMagickVersion(true)                    = '.$this->ImageMagickVersion(true);
  3501.         $DebugOutput['';
  3502.  
  3503.         $DebugOutput['$this->config_cache_directory               = '.$this->phpThumbDebugVarDump($this->config_cache_directory);
  3504.         $DebugOutput['$this->config_cache_directory_depth         = '.$this->phpThumbDebugVarDump($this->config_cache_directory_depth);
  3505.         $DebugOutput['$this->config_cache_disable_warning         = '.$this->phpThumbDebugVarDump($this->config_cache_disable_warning);
  3506.         $DebugOutput['$this->config_cache_maxage                  = '.$this->phpThumbDebugVarDump($this->config_cache_maxage);
  3507.         $DebugOutput['$this->config_cache_maxsize                 = '.$this->phpThumbDebugVarDump($this->config_cache_maxsize);
  3508.         $DebugOutput['$this->config_cache_maxfiles                = '.$this->phpThumbDebugVarDump($this->config_cache_maxfiles);
  3509.         $DebugOutput['$this->config_cache_force_passthru          = '.$this->phpThumbDebugVarDump($this->config_cache_force_passthru);
  3510.         $DebugOutput['$this->cache_filename                       = '.$this->phpThumbDebugVarDump($this->cache_filename);
  3511.         $DebugOutput['is_readable($this->config_cache_directory)  = '.$this->phpThumbDebugVarDump(@is_readable($this->config_cache_directory));
  3512.         $DebugOutput['is_writable($this->config_cache_directory)  = '.$this->phpThumbDebugVarDump(@is_writable($this->config_cache_directory));
  3513.         $DebugOutput['is_readable($this->cache_filename)          = '.$this->phpThumbDebugVarDump(@is_readable($this->cache_filename));
  3514.         $DebugOutput['is_writable($this->cache_filename)          = '.(@file_exists($this->cache_filename$this->phpThumbDebugVarDump(@is_writable($this->cache_filename)) 'n/a');
  3515.         $DebugOutput['';
  3516.  
  3517.         foreach ($ConfigVariableNames as $varname{
  3518.             $varname 'config_'.$varname;
  3519.             $value $this->$varname;
  3520.             $DebugOutput['$this->'.str_pad($varname37' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
  3521.         }
  3522.         $DebugOutput['';
  3523.         foreach ($OtherVariableNames as $varname{
  3524.             $value $this->$varname;
  3525.             $DebugOutput['$this->'.str_pad($varname27' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
  3526.         }
  3527.         $DebugOutput['strlen($this->rawImageData)        = '.strlen(@$this->rawImageData);
  3528.         $DebugOutput['strlen($this->exif_thumbnail_data) = '.strlen(@$this->exif_thumbnail_data);
  3529.         $DebugOutput['';
  3530.  
  3531.         foreach ($ParameterNames as $varname{
  3532.             $value $this->$varname;
  3533.             $DebugOutput['$this->'.str_pad($varname4' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
  3534.         }
  3535.         $DebugOutput['';
  3536.  
  3537.         foreach ($FunctionsExistance as $functionname{
  3538.             $DebugOutput['builtin_function_exists('.$functionname.')'.str_repeat(' '23 strlen($functionname)).' = '.$this->phpThumbDebugVarDump(phpthumb_functions::builtin_function_exists($functionname));
  3539.         }
  3540.         $DebugOutput['';
  3541.  
  3542.         $gd_info gd_info();
  3543.         foreach ($gd_info as $key => $value{
  3544.             $DebugOutput['gd_info.'.str_pad($key34' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
  3545.         }
  3546.         $DebugOutput['';
  3547.  
  3548.         $exif_info phpthumb_functions::exif_info();
  3549.         foreach ($exif_info as $key => $value{
  3550.             $DebugOutput['exif_info.'.str_pad($key26' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
  3551.         }
  3552.         $DebugOutput['';
  3553.  
  3554.         if ($ApacheLookupURIarray phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
  3555.             foreach ($ApacheLookupURIarray as $key => $value{
  3556.                 $DebugOutput['ApacheLookupURIarray.'.str_pad($key15' 'STR_PAD_RIGHT).' = '.$this->phpThumbDebugVarDump($value);
  3557.             }
  3558.         else {
  3559.                 $DebugOutput['ApacheLookupURIarray() -- FAILED';
  3560.         }
  3561.         $DebugOutput['';
  3562.  
  3563.         if (isset($_GET&& is_array($_GET)) {
  3564.             foreach ($_GET as $key => $value{
  3565.                 $DebugOutput['$_GET['.$key.']'.str_repeat(' '30 strlen($key)).'= '.$this->phpThumbDebugVarDump($value);
  3566.             }
  3567.         }
  3568.         if (isset($_POST&& is_array($_POST)) {
  3569.             foreach ($_POST as $key => $value{
  3570.                 $DebugOutput['$_POST['.$key.']'.str_repeat(' '29 strlen($key)).'= '.$this->phpThumbDebugVarDump($value);
  3571.             }
  3572.         }
  3573.         $DebugOutput['';
  3574.  
  3575.         $DebugOutput['$this->debugmessages:';
  3576.         foreach ($this->debugmessages as $errorstring{
  3577.             $DebugOutput['  * '.$errorstring;
  3578.         }
  3579.         $DebugOutput['';
  3580.  
  3581.         $DebugOutput['$this->debugtiming:';
  3582.         foreach ($this->debugtiming as $timestamp => $timingstring{
  3583.             $DebugOutput['  * '.$timestamp.' '.$timingstring;
  3584.         }
  3585.         $DebugOutput['  * Total processing time: '.number_format(max(array_keys($this->debugtiming)) min(array_keys($this->debugtiming))6);
  3586.  
  3587.         $this->f (isset($_GET['f']$_GET['f'$this->f)// debug modes 0-2 don't recognize text mode otherwise
  3588.         return $this->ErrorImage(implode("\n"$DebugOutput)700500true);
  3589.     }
  3590.  
  3591.     function FatalError($text{
  3592.         if (is_null($this->fatalerror)) {
  3593.             $this->fatalerror $text;
  3594.         }
  3595.         return true;
  3596.     }
  3597.  
  3598.     function ErrorImage($text$width=0$height=0$forcedisplay=false{
  3599.         $width  ($width  $width  $this->config_error_image_width);
  3600.         $height ($height $height $this->config_error_image_height);
  3601.  
  3602.         $text 'phpThumb() v'.$this->phpthumb_version."\n\n".$text;
  3603.         if ($this->config_disable_debug{
  3604.             $text 'Error messages disabled';
  3605.         }
  3606.  
  3607.         $this->FatalError($text);
  3608.         $this->DebugMessage($text__FILE____LINE__);
  3609.         if ($this->phpThumbDebug && !$forcedisplay{
  3610.             return false;
  3611.         }
  3612.         if (!$this->config_error_die_on_error && !$forcedisplay{
  3613.             return false;
  3614.         }
  3615.         if ($this->config_error_silent_die_on_error{
  3616.             exit;
  3617.         }
  3618.         if ($this->err || $this->config_error_message_image_default{
  3619.             // Show generic custom error image instead of error message
  3620.             // for use on production sites where you don't want debug messages
  3621.             if ($this->err == 'showerror'{
  3622.                 // fall through and actually show error message even if default error image is set
  3623.             else {
  3624.                 header('Location: '.($this->err $this->err $this->config_error_message_image_default));
  3625.                 exit;
  3626.             }
  3627.         }
  3628.         $this->setOutputFormat();
  3629.         if (!$this->thumbnailFormat || (phpthumb_functions::gd_version(1)) {
  3630.             $this->thumbnailFormat 'text';
  3631.         }
  3632.         if (@$this->thumbnailFormat == 'text'{
  3633.             // bypass all GD functions and output text error message
  3634.             if (!headers_sent()) {
  3635.                 header('Content-type: text/plain');
  3636.                 echo $text;
  3637.             else {
  3638.                 echo '<pre>'.htmlspecialchars($text).'</pre>';
  3639.             }
  3640.             exit;
  3641.         }
  3642.  
  3643.         $FontWidth  ImageFontWidth($this->config_error_fontsize);
  3644.         $FontHeight ImageFontHeight($this->config_error_fontsize);
  3645.  
  3646.         $LinesOfText explode("\n"@wordwrap($textfloor($width $FontWidth)"\n"true));
  3647.         $height max($heightcount($LinesOfText$FontHeight);
  3648.  
  3649.         $headers_file '';
  3650.         $headers_line '';
  3651.         if (phpthumb_functions::version_compare_replacement(phpversion()'4.3.0''>='&& headers_sent($headers_file$headers_line)) {
  3652.  
  3653.             echo "\n".'**Headers already sent in file "'.$headers_file.'" on line "'.$headers_line.'", dumping error message as text:**<br><pre>'."\n\n".$text."\n".'</pre>';
  3654.  
  3655.         elseif (headers_sent()) {
  3656.  
  3657.             echo "\n".'**Headers already sent, dumping error message as text:**<br><pre>'."\n\n".$text."\n".'</pre>';
  3658.  
  3659.         elseif ($gdimg_error ImageCreate($width$height)) {
  3660.  
  3661.             $background_color phpthumb_functions::ImageHexColorAllocate($gdimg_error$this->config_error_bgcolor,   true);
  3662.             $text_color       phpthumb_functions::ImageHexColorAllocate($gdimg_error$this->config_error_textcolortrue);
  3663.             ImageFilledRectangle($gdimg_error00$width$height$background_color);
  3664.             $lineYoffset 0;
  3665.             foreach ($LinesOfText as $line{
  3666.                 ImageString($gdimg_error$this->config_error_fontsize2$lineYoffset$line$text_color);
  3667.                 $lineYoffset += $FontHeight;
  3668.             }
  3669.             if (function_exists('ImageTypes')) {
  3670.                 $imagetypes ImageTypes();
  3671.                 if ($imagetypes IMG_PNG{
  3672.                     header('Content-Type: image/png');
  3673.                     ImagePNG($gdimg_error);
  3674.                 elseif ($imagetypes IMG_GIF{
  3675.                     header('Content-Type: image/gif');
  3676.                     ImageGIF($gdimg_error);
  3677.                 elseif ($imagetypes IMG_JPG{
  3678.                     header('Content-Type: image/jpeg');
  3679.                     ImageJPEG($gdimg_error);
  3680.                 elseif ($imagetypes IMG_WBMP{
  3681.                     header('Content-Type: image/vnd.wap.wbmp');
  3682.                     ImageWBMP($gdimg_error);
  3683.                 }
  3684.             }
  3685.             ImageDestroy($gdimg_error);
  3686.  
  3687.         }
  3688.         if (!headers_sent()) {
  3689.             echo "\n".'**Failed to send graphical error image, dumping error message as text:**<br>'."\n\n".$text;
  3690.         }
  3691.         exit;
  3692.         return true;
  3693.     }
  3694.  
  3695.     function ImageCreateFromStringReplacement(&$RawImageData$DieOnErrors=false{
  3696.         // there are serious bugs in the non-bundled versions of GD which may cause
  3697.         // PHP to segfault when calling ImageCreateFromString() - avoid if at all possible
  3698.         // when not using a bundled version of GD2
  3699.         if (!phpthumb_functions::gd_version()) {
  3700.             if ($DieOnErrors{
  3701.                 if (!headers_sent()) {
  3702.                     // base64-encoded error image in GIF format
  3703.                     $ERROR_NOGD 'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
  3704.                     header('Content-Type: image/gif');
  3705.                     echo base64_decode($ERROR_NOGD);
  3706.                 else {
  3707.                     echo '*** ERROR: No PHP-GD support available ***';
  3708.                 }
  3709.                 exit;
  3710.             else {
  3711.                 $this->DebugMessage('ImageCreateFromStringReplacement() failed: gd_version says "'.phpthumb_functions::gd_version().'"'__FILE____LINE__);
  3712.                 return false;
  3713.             }
  3714.         }
  3715.         if (phpthumb_functions::gd_is_bundled()) {
  3716.             $this->DebugMessage('ImageCreateFromStringReplacement() calling built-in ImageCreateFromString()'__FILE____LINE__);
  3717.             return @ImageCreateFromString($RawImageData);
  3718.         }
  3719.         if (ini_get('safe_mode')) {
  3720.             $this->DebugMessage('ImageCreateFromStringReplacement() failed: cannot create temp file in SAFE_MODE'__FILE____LINE__);
  3721.             return false;
  3722.         }
  3723.  
  3724.         switch (substr($RawImageData03)) {
  3725.             case 'GIF':
  3726.                 $ICFSreplacementFunctionName 'ImageCreateFromGIF';
  3727.                 break;
  3728.             case "\xFF\xD8\xFF":
  3729.                 $ICFSreplacementFunctionName 'ImageCreateFromJPEG';
  3730.                 break;
  3731.             case "\x89".'PN':
  3732.                 $ICFSreplacementFunctionName 'ImageCreateFromPNG';
  3733.                 break;
  3734.             default:
  3735.                 $this->DebugMessage('ImageCreateFromStringReplacement() failed: unknown fileformat signature "'.phpthumb_functions::HexCharDisplay(substr($RawImageData03)).'"'__FILE____LINE__);
  3736.                 return false;
  3737.                 break;
  3738.         }
  3739.         if ($tempnam $this->phpThumb_tempnam()) {
  3740.             if ($fp_tempnam @fopen($tempnam'wb')) {
  3741.                 fwrite($fp_tempnam$RawImageData);
  3742.                 fclose($fp_tempnam);
  3743.                 if (($ICFSreplacementFunctionName == 'ImageCreateFromGIF'&& !function_exists($ICFSreplacementFunctionName)) {
  3744.  
  3745.                     // Need to create from GIF file, but ImageCreateFromGIF does not exist
  3746.                     ob_start();
  3747.                     if (!@include_once(dirname(__FILE__).'/phpthumb.gif.php')) {
  3748.                         $ErrorMessage 'Failed to include required file "'.dirname(__FILE__).'/phpthumb.gif.php" in '.__FILE__.' on line '.__LINE__;
  3749.                         $this->DebugMessage($ErrorMessage__FILE____LINE__);
  3750.                     }
  3751.                     ob_end_clean();
  3752.                     // gif_loadFileToGDimageResource() cannot read from raw data, write to file first
  3753.                     if ($tempfilename $this->phpThumb_tempnam()) {
  3754.                         if ($fp_tempfile @fopen($tempfilename'wb')) {
  3755.                             fwrite($fp_tempfile$RawImageData);
  3756.                             fclose($fp_tempfile);
  3757.                             $gdimg_source gif_loadFileToGDimageResource($tempfilename);
  3758.                             $this->DebugMessage('gif_loadFileToGDimageResource('.$tempfilename.') completed'__FILE____LINE__);
  3759.                             unlink($tempfilename);
  3760.                             return $gdimg_source;
  3761.                             break;
  3762.                         else {
  3763.                             $ErrorMessage 'Failed to open tempfile in '.__FILE__.' on line '.__LINE__;
  3764.                             $this->DebugMessage($ErrorMessage__FILE____LINE__);
  3765.                         }
  3766.                     else {
  3767.                         $ErrorMessage 'Failed to open generate tempfile name in '.__FILE__.' on line '.__LINE__;
  3768.                         $this->DebugMessage($ErrorMessage__FILE____LINE__);
  3769.                     }
  3770.  
  3771.                 elseif (function_exists($ICFSreplacementFunctionName&& ($gdimg_source @$ICFSreplacementFunctionName($tempnam))) {
  3772.  
  3773.                     // great
  3774.                     $this->DebugMessage($ICFSreplacementFunctionName.'('.$tempnam.') succeeded'__FILE____LINE__);
  3775.                     unlink($tempnam);
  3776.                     return $gdimg_source;
  3777.  
  3778.                 else {
  3779.  
  3780.                     // GD functions not available, or failed to create image
  3781.                     $this->DebugMessage($ICFSreplacementFunctionName.'('.$tempnam.') '.(function_exists($ICFSreplacementFunctionName'failed' 'does not exist')__FILE____LINE__);
  3782.                     if (isset($_GET['phpThumbDebug'])) {
  3783.                         $this->phpThumbDebug();
  3784.                     }
  3785.  
  3786.                 }
  3787.             else {
  3788.                 $ErrorMessage 'Failed to fopen('.$tempnam.', "wb") in '.__FILE__.' on line '.__LINE__."\n".'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
  3789.                 $this->DebugMessage($ErrorMessage__FILE____LINE__);
  3790.             }
  3791.             @unlink($tempnam);
  3792.         else {
  3793.             $ErrorMessage 'Failed to generate phpThumb_tempnam() in '.__FILE__.' on line '.__LINE__."\n".'You may need to set $PHPTHUMB_CONFIG[temp_directory] in phpThumb.config.php';
  3794.         }
  3795.         if ($DieOnErrors && $ErrorMessage{
  3796.             return $this->ErrorImage($ErrorMessage);
  3797.         }
  3798.         return false;
  3799.     }
  3800.  
  3801.     function ImageResizeFunction(&$dst_im&$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH{
  3802.         $this->DebugMessage('ImageResizeFunction($o, $s, '.$dstX.', '.$dstY.', '.$srcX.', '.$srcY.', '.$dstW.', '.$dstH.', '.$srcW.', '.$srcH.')'__FILE____LINE__);
  3803.         if (($dstW == $srcW&& ($dstH == $srcH)) {
  3804.             return ImageCopy($dst_im$src_im$dstX$dstY$srcX$srcY$srcW$srcH);
  3805.         }
  3806.         if (phpthumb_functions::gd_version(>= 2.0{
  3807.             if ($this->config_disable_imagecopyresampled{
  3808.                 return phpthumb_functions::ImageCopyResampleBicubic($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH);
  3809.             }
  3810.             return ImageCopyResampled($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH);
  3811.         }
  3812.         return ImageCopyResized($dst_im$src_im$dstX$dstY$srcX$srcY$dstW$dstH$srcW$srcH);
  3813.     }
  3814.  
  3815.     function InitializeTempDirSetting({
  3816.         $this->config_temp_directory realpath($this->config_temp_directory $this->config_temp_directory (getenv('TMPDIR'getenv('TMPDIR'getenv('TMP')));
  3817.         return true;
  3818.     }
  3819.  
  3820.     function phpThumb_tempnam({
  3821.         $this->InitializeTempDirSetting();
  3822.         $tempnam realpath(tempnam($this->config_temp_directory'pThumb'));
  3823.         $this->DebugMessage('phpThumb_tempnam() returning "'.$tempnam.'"'__FILE____LINE__);
  3824.         return $tempnam;
  3825.     }
  3826.  
  3827.     function DebugMessage($message$file=''$line=''{
  3828.         $this->debugmessages[$message.($file ' in file "'.(basename($filebasename($file$file).'"' '').($line ' on line '.$line '');
  3829.         return true;
  3830.     }
  3831.  
  3832.     function DebugTimingMessage($message$file=''$line=''$timestamp=0{
  3833.         if (!$timestamp{
  3834.             $timestamp array_sum(explode(' 'microtime()));
  3835.         }
  3836.         $this->debugtiming[number_format($timestamp6'.''')': '.$message.($file ' in file "'.(basename($filebasename($file$file).'"' '').($line ' on line '.$line '');
  3837.         return true;
  3838.     }
  3839.  
  3840. }
  3841.  
  3842. ?>

Documentation generated on Fri, 18 Jul 2008 21:48:59 +0200 by phpDocumentor 1.4.1