/cms113/phpthumb.class.php
PHP | 2388 lines | 1927 code | 323 blank | 138 comment | 426 complexity | 290e8cf2252daf3dd0edfdff5db0ae68 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1
Large files files are truncated, but you can click here to view the full file
- <?php
- //////////////////////////////////////////////////////////////
- /// phpthumb() by James Heinrich <info@silisoftware.com> //
- // available at http://phpthumb.sourceforge.net ///
- //////////////////////////////////////////////////////////////
- /// //
- // See: phpthumb.readme.txt for usage instructions //
- // ///
- //////////////////////////////////////////////////////////////
-
- ob_start();
- if (!include_once(dirname(__FILE__).'/phpthumb.functions.php')) {
- ob_end_flush();
- die('(phpthumb.class.php) failed to include_once("'.realpath(dirname(__FILE__).'/phpthumb.functions.php').'")');
- }
- ob_end_clean();
-
- class phpthumb {
-
- // public:
- // START PARAMETERS (for object mode and phpthumb.php)
- // See phpthumb.readme.txt for descriptions of what each of these values are
- var $src = null; // SouRCe filename
- var $new = null; // NEW image (phpthumb.php only)
- var $w = null; // Width
- var $h = null; // Height
- var $f = null; // Format
- var $q = 75; // Quality
- var $sx = null; // Source crop top-left X position
- var $sy = null; // Source crop top-left Y position
- var $sw = null; // Source crop Width
- var $sh = null; // Source crop Height
- var $zc = null; // Zoom Crop
- var $bc = null; // Border Color
- var $bg = null; // BackGround color
- var $fltr = array(); // FiLTeRs
- var $file = null; // render-to FILEname
- var $goto = null; // GO TO url after processing
- var $err = null; // default ERRor image filename
- var $xto = null; // extract eXif Thumbnail Only
- var $ra = null; // Rotate by Angle
- var $ar = null; // Auto Rotate
- var $aoe = null; // Allow Output Enlargement
- var $far = null; // Fixed Aspect Ratio
- var $iar = null; // Ignore Aspect Ratio
- var $maxb = null; // MAXimum Bytes
- var $down = null; // DOWNload thumbnail
- var $md5s = null; // MD5 hash of Source image
-
- var $phpthumbDebug = null;
- // END PARAMETERS
-
-
- // public:
- // START CONFIGURATION OPTIONS (for object mode only)
- // See phpthumb.config.php for descriptions of what each of these settings do
-
- // * Directory Configuration
- var $config_cache_directory = null;
- var $config_cache_disable_warning = true;
- var $config_cache_source_enabled = false;
- var $config_cache_source_directory = null;
- var $config_temp_directory = null;
- var $config_document_root = null;
-
- // * Default output configuration:
- var $config_output_format = 'jpeg';
- var $config_output_maxwidth = 0;
- var $config_output_maxheight = 0;
- var $config_output_interlace = true;
-
- // * Error message configuration
- var $config_error_image_width = 400;
- var $config_error_image_height = 100;
- var $config_error_message_image_default = '';
- var $config_error_bgcolor = 'CCCCFF';
- var $config_error_textcolor = 'FF0000';
- var $config_error_fontsize = 1;
- var $config_error_die_on_error = true;
- var $config_error_silent_die_on_error = false;
- var $config_error_die_on_source_failure = true;
-
- // * Anti-Hotlink Configuration:
- var $config_nohotlink_enabled = true;
- var $config_nohotlink_valid_domains = array();
- var $config_nohotlink_erase_image = true;
- var $config_nohotlink_text_message = 'Off-server thumbnailing is not allowed';
- // * Off-server Linking Configuration:
- var $config_nooffsitelink_enabled = false;
- var $config_nooffsitelink_valid_domains = array();
- var $config_nooffsitelink_require_refer = false;
- var $config_nooffsitelink_erase_image = true;
- var $config_nooffsitelink_text_message = 'Off-server linking is not allowed';
-
- // * Border & Background default colors
- var $config_border_hexcolor = '000000';
- var $config_background_hexcolor = 'FFFFFF';
-
- // * TrueType Fonts
- var $config_ttf_directory = '.';
-
- var $config_max_source_pixels = 0;
- var $config_use_exif_thumbnail_for_speed = true;
- var $config_output_allow_enlarging = false;
-
- var $config_imagemagick_path = null;
-
- var $config_cache_maxage = null;
- var $config_cache_maxsize = null;
- var $config_cache_maxfiles = null;
-
- var $config_cache_source_filemtime_ignore_local = false;
- var $config_cache_source_filemtime_ignore_remote = false;
-
- var $config_disable_debug = false;
- // END CONFIGURATION OPTIONS
-
-
- // public: error messages (read-only)
- var $debugmessages = array();
- var $fatalerror = null;
-
-
- // private: (should not be modified directly)
- var $thumbnailQuality = 75;
- var $thumbnailFormat = null;
-
- var $sourceFilename = null;
- var $rawImageData = null;
-
- var $gdimg_output = null;
- var $gdimg_source = null;
-
- var $getimagesizeinfo = null;
-
- var $source_width = null;
- var $source_height = null;
-
- var $thumbnailCropX = null;
- var $thumbnailCropY = null;
- var $thumbnailCropW = null;
- var $thumbnailCropH = null;
-
- var $exif_thumbnail_width = null;
- var $exif_thumbnail_height = null;
- var $exif_thumbnail_type = null;
- var $exif_thumbnail_data = null;
-
- var $thumbnail_width = null;
- var $thumbnail_height = null;
- var $thumbnail_image_width = null;
- var $thumbnail_image_height = null;
-
- var $cache_filename = null;
-
- var $is_alpha = false;
-
- var $iswindows = null;
- var $osslash = null;
-
- var $phpthumb_version = '1.5.4-200505261715';
-
- //////////////////////////////////////////////////////////////////////
-
- // public: constructor
- function phpthumb() {
- if (phpthumb_functions::gd_version() < 1) {
- die('No GD support detected');
- }
- if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') {
- $this->iswindows = true;
- $this->osslash = '\\';
- } else {
- $this->iswindows = false;
- $this->osslash = '/';
- }
- if (!empty($_SERVER['DOCUMENT_ROOT'])) {
- $this->config_document_root = $_SERVER['DOCUMENT_ROOT'];
- }
- }
-
- // public:
- function setSourceFilename($sourceFilename) {
- $this->rawImageData = null;
- $this->sourceFilename = $sourceFilename;
- return true;
- }
-
- // public:
- function setSourceData($rawImageData, $sourceFilename='') {
- $this->sourceFilename = null;
- $this->rawImageData = $rawImageData;
- if ($this->config_cache_source_enabled) {
- $sourceFilename = ($sourceFilename ? $sourceFilename : md5($rawImageData));
- if (!is_dir($this->config_cache_source_directory) && !$this->phpthumbDebug) {
- $this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not a directory');
- } elseif (!is_writable($this->config_cache_source_directory) && !$this->phpthumbDebug) {
- $this->ErrorImage('$this->config_cache_source_directory ('.$this->config_cache_source_directory.') is not writable');
- }
- $this->DebugMessage('setSourceData() attempting to save source image to "'.$this->config_cache_source_directory.'/'.urlencode($sourceFilename).'"', __FILE__, __LINE__);
- if ($fp = @fopen($this->config_cache_source_directory.'/'.urlencode($sourceFilename), 'wb')) {
- fwrite($fp, $rawImageData);
- fclose($fp);
- } elseif (!$this->phpthumbDebug) {
- $this->ErrorImage('setSourceData() failed to write to source cache ('.$this->config_cache_source_directory.'/'.urlencode($sourceFilename).')');
- }
- }
- return true;
- }
-
- // public:
- function setSourceImageResource($gdimg) {
- $this->gdimg_source = $gdimg;
- return true;
- }
-
-
-
- // public:
- function GenerateThumbnail() {
-
- $this->setOutputFormat();
- $this->ResolveSource();
- $this->SetCacheFilename();
- $this->ExtractEXIFgetImageSize();
- if (!$this->SourceImageToGD()) {
- return false;
- }
- $this->Rotate();
- $this->CreateGDoutput();
-
- // copy/resize image to appropriate dimensions (either nearest-neighbor or resample, depending on GD version)
- phpthumb_functions::ImageResizeFunction(
- $this->gdimg_output,
- $this->gdimg_source,
- round(($this->thumbnail_width - $this->thumbnail_image_width) / 2),
- round(($this->thumbnail_height - $this->thumbnail_image_height) / 2),
- $this->thumbnailCropX,
- $this->thumbnailCropY,
- $this->thumbnail_image_width,
- $this->thumbnail_image_height,
- $this->thumbnailCropW,
- $this->thumbnailCropH
- );
-
-
- $this->AntiOffsiteLinking();
- $this->ApplyFilters();
- $this->AlphaChannelFlatten();
- $this->MaxFileSize();
-
- return true;
- }
-
-
- // public:
- function RenderToFile($filename) {
- if (!is_resource($this->gdimg_output)) {
- $this->DebugMessage('RenderToFile('.$filename.') failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
- return false;
- }
- if (!$this->thumbnailFormat) {
- $this->DebugMessage('RenderToFile() failed because $this->thumbnailFormat is empty', __FILE__, __LINE__);
- return false;
- }
- // render thumbnail to this file only, do not cache, do not output to browser
- $ImageOutFunction = 'image'.$this->thumbnailFormat;
- //$renderfilename = $this->ResolveFilenameToAbsolute(dirname($filename)).'/'.basename($filename);
- $renderfilename = $filename;
- if (($filename{0} != '/') && ($filename{0} != '\\') && ($filename{1} != ':')) {
- $renderfilename = $this->ResolveFilenameToAbsolute($filename);
- }
- $this->DebugMessage('RenderToFile('.$filename.') attempting '.$ImageOutFunction.'($this->gdimg_output, '.$renderfilename.')', __FILE__, __LINE__);
- ob_start();
- switch ($this->thumbnailFormat) {
- case 'jpeg':
- $ImageOutFunction($this->gdimg_output, $renderfilename, $this->thumbnailQuality);
- break;
-
- case 'png':
- case 'gif':
- $ImageOutFunction($this->gdimg_output, $renderfilename);
- break;
- }
- $errormessage = strip_tags(ob_get_contents());
- ob_end_clean();
- if ($errormessage) {
- $this->DebugMessage('RenderToFile ['.$ImageOutFunction.'('.$renderfilename.')] failed with message "'.$errormessage.'"', __FILE__, __LINE__);
- return false;
- } elseif (!file_exists($renderfilename)) {
- $this->DebugMessage('RenderToFile ['.$ImageOutFunction.'('.$renderfilename.')] did not appear to fail, but the output image does not exist either...', __FILE__, __LINE__);
- }
- return true;
- }
-
-
- // public:
- function OutputThumbnail() {
- if (!is_resource($this->gdimg_output)) {
- $this->DebugMessage('OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
- return false;
- }
- if (headers_sent()) {
- return $this->ErrorImage('OutputThumbnail() failed - headers already sent');
- exit;
- }
-
- if (!empty($this->down)) {
- $downloadfilename = ereg_replace('[/\\:\*\?"<>|]', '_', $this->down);
- if (phpthumb_functions::version_compare_replacement(phpversion(), '4.1.0', '>=')) {
- $downloadfilename = trim($downloadfilename, '.');
- }
- if ($downloadfilename != $this->down) {
- $this->DebugMessage('renaming output file for "down" from "'.$this->down.'" to "'.$downloadfilename.'"', __FILE__, __LINE__);
- }
- if ($downloadfilename) {
- header('Content-Disposition: attachment; filename="'.$downloadfilename.'"');
- } else {
- $this->DebugMessage('failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__);
- }
- }
-
- ImageInterlace($this->gdimg_output, intval($this->config_output_interlace));
- $ImageOutFunction = 'image'.$this->thumbnailFormat;
- switch ($this->thumbnailFormat) {
- case 'jpeg':
- header('Content-Type: image/'.$this->thumbnailFormat);
- @$ImageOutFunction($this->gdimg_output, '', $this->thumbnailQuality);
- break;
-
- case 'png':
- case 'gif':
- header('Content-Type: image/'.$this->thumbnailFormat);
- @$ImageOutFunction($this->gdimg_output);
- break;
-
- default:
- return false;
- break;
- }
- ImageDestroy($this->gdimg_output);
- return true;
- }
-
-
- // public:
- function CleanUpCacheDirectory() {
- if (($this->config_cache_maxage > 0) || ($this->config_cache_maxsize > 0) || ($this->config_cache_maxfiles > 0)) {
- $CacheDirOldFilesAge = array();
- $CacheDirOldFilesSize = array();
- if ($dirhandle = opendir($this->config_cache_directory)) {
- while ($oldcachefile = readdir($dirhandle)) {
- if (eregi('^phpthumb_cache_', $oldcachefile)) {
- $CacheDirOldFilesAge[$oldcachefile] = fileatime($this->config_cache_directory.'/'.$oldcachefile);
- if ($CacheDirOldFilesAge[$oldcachefile] == 0) {
- $CacheDirOldFilesAge[$oldcachefile] = filemtime($this->config_cache_directory.'/'.$oldcachefile);
- }
-
- $CacheDirOldFilesSize[$oldcachefile] = filesize($this->config_cache_directory.'/'.$oldcachefile);
- }
- }
- }
- asort($CacheDirOldFilesAge);
-
- if ($this->config_cache_maxfiles > 0) {
- $TotalCachedFiles = count($CacheDirOldFilesAge);
- $DeletedKeys = array();
- foreach ($CacheDirOldFilesAge as $oldcachefile => $filedate) {
- if ($TotalCachedFiles > $this->config_cache_maxfiles) {
- $TotalCachedFiles--;
- if (@unlink($this->config_cache_directory.'/'.$oldcachefile)) {
- $DeletedKeys[] = $oldcachefile;
- }
- } else {
- // there are few enough files to keep the rest
- break;
- }
- }
- foreach ($DeletedKeys as $oldcachefile) {
- unset($CacheDirOldFilesAge[$oldcachefile]);
- unset($CacheDirOldFilesSize[$oldcachefile]);
- }
- }
-
- if ($this->config_cache_maxage > 0) {
- $mindate = time() - $this->config_cache_maxage;
- $DeletedKeys = array();
- foreach ($CacheDirOldFilesAge as $oldcachefile => $filedate) {
- if ($filedate > 0) {
- if ($filedate < $mindate) {
- if (@unlink($this->config_cache_directory.'/'.$oldcachefile)) {
- $DeletedKeys[] = $oldcachefile;
- }
- } else {
- // the rest of the files are new enough to keep
- break;
- }
- }
- }
- foreach ($DeletedKeys as $oldcachefile) {
- unset($CacheDirOldFilesAge[$oldcachefile]);
- unset($CacheDirOldFilesSize[$oldcachefile]);
- }
- }
-
- if ($this->config_cache_maxsize > 0) {
- $TotalCachedFileSize = array_sum($CacheDirOldFilesSize);
- $DeletedKeys = array();
- foreach ($CacheDirOldFilesAge as $oldcachefile => $filedate) {
- if ($TotalCachedFileSize > $this->config_cache_maxsize) {
- $TotalCachedFileSize -= $CacheDirOldFilesSize[$oldcachefile];
- if (@unlink($this->config_cache_directory.'/'.$oldcachefile)) {
- $DeletedKeys[] = $oldcachefile;
- }
- } else {
- // the total filesizes are small enough to keep the rest of the files
- break;
- }
- }
- foreach ($DeletedKeys as $oldcachefile) {
- unset($CacheDirOldFilesAge[$oldcachefile]);
- unset($CacheDirOldFilesSize[$oldcachefile]);
- }
- }
-
- }
- return true;
- }
-
- //////////////////////////////////////////////////////////////////////
-
- function ResolveSource() {
- if (is_resource($this->gdimg_source)) {
- return true;
- }
- if (empty($this->sourceFilename) && empty($this->rawImageData)) {
- $this->sourceFilename = $this->ResolveFilenameToAbsolute($this->src);
- }
- return true;
- }
-
- function setOutputFormat() {
- static $alreadyCalled = false;
- if ($this->thumbnailFormat && $alreadyCalled) {
- return true;
- }
- $alreadyCalled = true;
-
- $AvailableImageOutputFormats = array();
- $AvailableImageOutputFormats[] = 'text';
- $this->thumbnailFormat = 'text';
-
- // Set default output format based on what image types are available
- if (!function_exists('ImageTypes')) {
- return $this->ErrorImage('ImageTypes() does not exist - GD support might not be enabled?');
- }
- $imagetypes = ImageTypes();
- if ($imagetypes & IMG_WBMP) {
- $this->thumbnailFormat = 'wbmp';
- $AvailableImageOutputFormats[] = 'wbmp';
- }
- if ($imagetypes & IMG_GIF) {
- $this->thumbnailFormat = 'gif';
- $AvailableImageOutputFormats[] = 'gif';
- }
- if ($imagetypes & IMG_PNG) {
- $this->thumbnailFormat = 'png';
- $AvailableImageOutputFormats[] = 'png';
- }
- if ($imagetypes & IMG_JPG) {
- $this->thumbnailFormat = 'jpeg';
- $AvailableImageOutputFormats[] = 'jpeg';
- }
- $this->DebugMessage('$AvailableImageOutputFormats = array('.implode(';', $AvailableImageOutputFormats).')', __FILE__, __LINE__);
-
- if (strtolower($this->config_output_format) == 'jpg') {
- $this->config_output_format = 'jpeg';
- }
- if (strtolower($this->f) == 'jpg') {
- $this->f = 'jpeg';
- }
- if (in_array(strtolower($this->config_output_format), $AvailableImageOutputFormats)) {
- // set output format to config default if that format is available
- $this->DebugMessage('$this->thumbnailFormat set to $this->config_output_format "'.strtolower($this->config_output_format).'"', __FILE__, __LINE__);
- $this->thumbnailFormat = strtolower($this->config_output_format);
- } else {
- $this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because "'.strtolower($this->config_output_format).'" ($this->config_output_format) is not in $AvailableImageOutputFormats', __FILE__, __LINE__);
- }
- if ($this->f && (in_array(strtolower($this->f), $AvailableImageOutputFormats))) {
- // override output format if $this->f is set and that format is available
- $this->DebugMessage('$this->thumbnailFormat set to $this->f "'.strtolower($this->f).'"', __FILE__, __LINE__);
- $this->thumbnailFormat = strtolower($this->f);
- } else {
- $this->DebugMessage('$this->thumbnailFormat staying as "'.$this->thumbnailFormat.'" because "'.strtolower($this->f).'" ($this->f) is not in $AvailableImageOutputFormats', __FILE__, __LINE__);
- }
-
- // for JPEG images, quality 1 (worst) to 99 (best)
- // quality < 25 is nasty, with not much size savings - not recommended
- // problems with 100 - invalid JPEG?
- $this->thumbnailQuality = max(1, min(99, (!empty($this->q) ? $this->q : 75)));
- $this->DebugMessage('$this->thumbnailQuality set to "'.$this->thumbnailQuality.'"', __FILE__, __LINE__);
-
- return true;
- }
-
- function setCacheDirectory() {
- // resolve cache directory to absolute pathname
- if (substr($this->config_cache_directory, 0, 1) == '.') {
- if (eregi('^(f|ht)tp[s]?://', $this->src)) {
- if (!$this->config_cache_disable_warning && !$this->phpthumbDebug) {
- $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');
- }
- } elseif ($this->src) {
- // resolve relative cache directory to source image
- $this->config_cache_directory = dirname($this->ResolveFilenameToAbsolute($this->src)).'/'.$this->config_cache_directory;
- } else {
- // $this->new is probably set
- }
- }
- if (substr($this->config_cache_directory, -1) == '/') {
- $this->config_cache_directory = substr($this->config_cache_directory, 0, -1);
- }
- if ($this->iswindows) {
- $this->config_cache_directory = str_replace('/', $this->osslash, $this->config_cache_directory);
- }
- if (!empty($this->config_cache_directory)) {
- $real_cache_path = realpath($this->config_cache_directory);
- if (!$real_cache_path) {
- $this->DebugMessage('realpath($this->config_cache_directory) failed for "'.$this->config_cache_directory.'"', __FILE__, __LINE__);
- if (!is_dir($this->config_cache_directory)) {
- $this->DebugMessage('!is_dir('.$this->config_cache_directory.')', __FILE__, __LINE__);
- }
- }
- if ($real_cache_path) {
- $this->config_cache_directory = $real_cache_path;
- }
- }
- if (!is_dir($this->config_cache_directory)) {
- if (!$this->config_cache_disable_warning && !$this->phpthumbDebug) {
- $this->ErrorImage('$this->config_cache_directory ('.$this->config_cache_directory.') does not exist. Adjust "cache_directory" or "cache_disable_warning" in phpthumb.config.php');
- }
- $this->DebugMessage('$this->config_cache_directory ('.$this->config_cache_directory.') is not a directory', __FILE__, __LINE__);
- $this->config_cache_directory = null;
- } elseif (!is_writable($this->config_cache_directory)) {
- $this->DebugMessage('$this->config_cache_directory is not writable ('.$this->config_cache_directory.')', __FILE__, __LINE__);
- }
- return true;
- }
-
-
- function ResolveFilenameToAbsolute($filename) {
- if (eregi('^(f|ht)tp[s]?://', $filename)) {
-
- // URL
- $AbsoluteFilename = $filename;
-
- } elseif ($this->iswindows && ($filename{1} == ':')) {
-
- // absolute pathname (Windows)
- $AbsoluteFilename = $filename;
-
- } elseif ($this->iswindows && ((substr($filename, 0, 2) == '//') || (substr($filename, 0, 2) == '\\\\'))) {
-
- // absolute pathname (Windows)
- $AbsoluteFilename = $filename;
-
- } elseif ($filename{0} == '/') {
-
- if (@is_readable($filename) && !@is_readable($this->config_document_root.$filename)) {
- // absolute filename (*nix)
- $AbsoluteFilename = $filename;
- } elseif ($filename{1} == '~') {
- // /~user/path
- if ($ApacheLookupURIarray = phpthumb_functions::ApacheLookupURIarray($filename)) {
- $AbsoluteFilename = $ApacheLookupURIarray['filename'];
- } else {
- $AbsoluteFilename = realpath($filename);
- if (@is_readable($AbsoluteFilename)) {
- $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'", but the correct filename ('.$AbsoluteFilename.') seems to have been resolved with realpath($filename)', __FILE__, __LINE__);
- } else {
- if ($this->phpthumbDebug) {
- $this->DebugMessage('phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.'". This has been known to fail on Apache2 - try using the absolute filename for the source image');
- return false;
- } else {
- 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');
- }
- }
- }
- } else {
- // relative filename (any OS)
- $AbsoluteFilename = $this->config_document_root.$filename;
- }
-
- } else {
-
- // relative to current directory (any OS)
- $AbsoluteFilename = $this->config_document_root.dirname(@$_SERVER['PHP_SELF']).'/'.$filename;
- //if (!file_exists($AbsoluteFilename) && file_exists(realpath($this->DotPadRelativeDirectoryPath($filename)))) {
- // $AbsoluteFilename = realpath($this->DotPadRelativeDirectoryPath($filename));
- //}
-
- if (substr(dirname(@$_SERVER['PHP_SELF']), 0, 2) == '/~') {
- if ($ApacheLookupURIarray = phpthumb_functions::ApacheLookupURIarray(dirname(@$_SERVER['PHP_SELF']))) {
- $AbsoluteFilename = $ApacheLookupURIarray['filename'].'/'.$filename;
- } else {
- $AbsoluteFilename = realpath('.').'/'.$filename;
- if (@is_readable($AbsoluteFilename)) {
- $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__);
- } else {
- 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');
- }
- }
- }
-
- }
- return $AbsoluteFilename;
- }
-
- function ImageMagickCommandlineBase() {
- static $commandline = null;
- if (is_null($commandline)) {
- $commandline = '';
-
- $which_convert = trim(phpthumb_functions::SafeBackTick('which convert'));
-
- if ($this->config_imagemagick_path && ($this->config_imagemagick_path != realpath($this->config_imagemagick_path))) {
- $this->DebugMessage('Changing $this->config_imagemagick_path ('.$this->config_imagemagick_path.') to realpath($this->config_imagemagick_path) ('.realpath($this->config_imagemagick_path).')', __FILE__, __LINE__);
- $this->config_imagemagick_path = realpath($this->config_imagemagick_path);
- }
- if (file_exists($this->config_imagemagick_path)) {
-
- $this->DebugMessage('using ImageMagick path from $this->config_imagemagick_path ('.$this->config_imagemagick_path.')', __FILE__, __LINE__);
- if ($this->iswindows) {
- $commandline = substr($this->config_imagemagick_path, 0, 2).' && cd "'.substr(dirname($this->config_imagemagick_path), 2).'" && '.basename($this->config_imagemagick_path);
- } else {
- $commandline = '"'.$this->config_imagemagick_path.'"';
- }
-
- } elseif ($which_convert && ($which_convert{0} == '/') && @file_exists($which_convert)) {
-
- // `which convert` *should* return the path if "convert" exist, or nothing if it doesn't
- // other things *may* get returned, like "sh: convert: not found" or "no convert in /usr/local/bin /usr/sbin /usr/bin /usr/ccs/bin"
- // so only do this if the value returned exists as a file
- $this->DebugMessage('using ImageMagick path from `which convert` ('.$which_convert.')', __FILE__, __LINE__);
- $commandline = 'convert';
-
- } else {
-
- $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__);
-
- }
- }
- return $commandline;
- }
-
- function ImageMagickVersion() {
- $commandline = $this->ImageMagickCommandlineBase();
- if (!empty($commandline)) {
- $commandline .= ' -version';
- $versionstring = phpthumb_functions::SafeBackTick($commandline);
- if (eregi('^Version: (.*) http', $versionstring, $matches)) {
- return $matches[1];
- }
- $this->DebugMessage('ImageMagick did not return recognized version string ('.$versionstring.')', __FILE__, __LINE__);
- return $versionstring;
- }
- return false;
- }
-
- function ImageMagickThumbnailToGD() {
- // http://freealter.org/doc_distrib/ImageMagick-5.1.1/www/convert.html
- if (ini_get('safe_mode')) {
- $this->DebugMessage('ImageMagickThumbnailToGD() aborting because safe_mode is enabled', __FILE__, __LINE__);
- return false;
- }
- if (!function_exists('ImageCreateFromPNG')) {
- // ImageMagickThumbnailToGD() depends on ImageCreateFromPNG()
- $this->DebugMessage('ImageMagickThumbnailToGD() aborting because ImageCreateFromPNG() is not available', __FILE__, __LINE__);
- return false;
- }
-
- $commandline = $this->ImageMagickCommandlineBase();
- if (!empty($commandline)) {
- if ($IMtempfilename = $this->phpthumb_tempnam()) {
-
- $IMtempfilename = realpath($IMtempfilename);
- $IMwidth = ((intval($this->w) > 0) ? intval($this->w) : 640);
- $IMheight = ((intval($this->h) > 0) ? intval($this->h) : 480);
- if (!$this->aoe && !$this->iar && ($getimagesize = @GetImageSize($this->sourceFilename))) {
- // limit output size to input size unless AllowOutputEnlargement is enabled
- $IMwidth = min($IMwidth, $getimagesize[0]);
- $IMheight = min($IMheight, $getimagesize[1]);
- }
- //$commandline .= ' -resize '.$IMwidth.'x'.$IMheight; // behaves badly with IM v5.3.x
- $commandline .= ' -geometry '.$IMwidth.'x'.$IMheight;
- if (!empty($this->iar) && (intval($this->w) > 0) && (intval($this->h) > 0)) {
- $commandline .= '!';
- }
- $commandline .= ' "'.str_replace('/', $this->osslash, $this->sourceFilename).'"';
- $commandline .= ' png:'.$IMtempfilename;
- $commandline .= ' 2>&1';
-
- $IMresult = phpthumb_functions::SafeBackTick($commandline);
- if (!empty($IMresult)) {
-
- //return $this->ErrorImage('ImageMagick was called as:'."\n".$commandline."\n\n".'but failed with message:'."\n".$IMresult);
- $this->DebugMessage('ImageMagick was called as ('.$commandline.') but failed with message ('.$IMresult.')', __FILE__, __LINE__);
-
- } elseif ($this->gdimg_source = @ImageCreateFromPNG($IMtempfilename)) {
-
- unlink($IMtempfilename);
- $this->source_width = ImageSX($this->gdimg_source);
- $this->source_height = ImageSY($this->gdimg_source);
- $this->DebugMessage('ImageMagickThumbnailToGD() succeeded, $this->gdimg_source is now ('.$this->source_width.'x'.$this->source_height.')', __FILE__, __LINE__);
- return true;
-
- }
- unlink($IMtempfilename);
-
- } else {
- $this->DebugMessage('ImageMagickThumbnailToGD() aborting, phpthumb_tempnam() failed', __FILE__, __LINE__);
- }
- }
- $this->DebugMessage('ImageMagickThumbnailToGD() aborting because ImageMagickCommandlineBase() failed', __FILE__, __LINE__);
- return false;
- }
-
-
- function Rotate() {
- if (!empty($this->ra) || !empty($this->ar)) {
- if (!function_exists('ImageRotate')) {
- $this->DebugMessage('!function_exists(ImageRotate)', __FILE__, __LINE__);
- return false;
- }
- if (!include_once(dirname(__FILE__).'/phpthumb.filters.php')) {
- $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';', $this->fltr).')', __FILE__, __LINE__);
- return false;
- }
-
- $this->config_background_hexcolor = (!empty($this->bg) ? $this->bg : $this->config_background_hexcolor);
- if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
- return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
- }
-
- $rotate_angle = 0;
- if (!empty($this->ra)) {
-
- $rotate_angle = floatval($this->ra);
-
- } else {
-
- if ($this->ar == 'x') {
- if (phpthumb_functions::version_compare_replacement(phpversion(), '4.2.0', '>=')) {
- if ($this->sourceFilename) {
- if (function_exists('exif_read_data')) {
- if ($exif_data = @exif_read_data($this->sourceFilename, 'IFD0')) {
- // http://sylvana.net/jpegcrop/exif_orientation.html
- switch (@$exif_data['Orientation']) {
- case 1:
- $rotate_angle = 0;
- break;
- case 3:
- $rotate_angle = 180;
- break;
- case 6:
- $rotate_angle = 270;
- break;
- case 8:
- $rotate_angle = 90;
- break;
-
- default:
- $this->DebugMessage('EXIF auto-rotate failed because unknown $exif_data[Orientation] "'.@$exif_data['Orientation'].'"', __FILE__, __LINE__);
- return false;
- break;
- }
- $this->DebugMessage('EXIF auto-rotate set to '.$rotate_angle.' degrees ($exif_data[Orientation] = "'.@$exif_data['Orientation'].'")', __FILE__, __LINE__);
- } else {
- $this->DebugMessage('failed: exif_read_data('.$this->sourceFilename.')', __FILE__, __LINE__);
- return false;
- }
- } else {
- $this->DebugMessage('!function_exists(exif_read_data)', __FILE__, __LINE__);
- return false;
- }
- } else {
- $this->DebugMessage('Cannot auto-rotate from EXIF data because $this->sourceFilename is empty', __FILE__, __LINE__);
- return false;
- }
- } else {
- $this->DebugMessage('Cannot auto-rotate from EXIF data because PHP is less than v4.2.0 ('.phpversion().')', __FILE__, __LINE__);
- return false;
- }
- } elseif (($this->ar == 'l') && ($this->source_height > $this->source_width)) {
- $rotate_angle = 270;
- } elseif (($this->ar == 'L') && ($this->source_height > $this->source_width)) {
- $rotate_angle = 90;
- } elseif (($this->ar == 'p') && ($this->source_width > $this->source_height)) {
- $rotate_angle = 90;
- } elseif (($this->ar == 'P') && ($this->source_width > $this->source_height)) {
- $rotate_angle = 270;
- }
-
- }
- while ($rotate_angle < 0) {
- $rotate_angle += 360;
- }
- $rotate_angle = $rotate_angle % 360;
- if ($rotate_angle != 0) {
-
- $background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_source, $this->config_background_hexcolor);
-
- if ((phpthumb_functions::gd_version() >= 2) && ($this->thumbnailFormat == 'png') && !$this->bg && ($rotate_angle % 90)) {
-
- if ($gdimg_rotate_mask = phpthumb_functions::ImageCreateFunction(ImageSX($this->gdimg_source), ImageSY($this->gdimg_source))) {
-
- $this->gdimg_source = ImageRotate($this->gdimg_source, $rotate_angle, $background_color);
- $color_mask_opaque = ImageColorAllocate($gdimg_rotate_mask, 0xFF, 0xFF, 0xFF);
- $color_mask_transparent = ImageColorAllocate($gdimg_rotate_mask, 0x00, 0x00, 0x00);
- ImageFilledRectangle($gdimg_rotate_mask, 0, 0, ImageSX($gdimg_rotate_mask), ImageSY($gdimg_rotate_mask), $color_mask_opaque);
- $gdimg_rotate_mask = ImageRotate($gdimg_rotate_mask, $rotate_angle, $color_mask_transparent);
-
- ImageAlphaBlending($this->gdimg_source, false);
- if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
- ImageSaveAlpha($this->gdimg_source, true);
- }
- $this->is_alpha = true;
- phpthumb_filters::ApplyMask($gdimg_rotate_mask, $this->gdimg_source);
-
- ImageDestroy($gdimg_rotate_mask);
- $this->source_width = ImageSX($this->gdimg_source);
- $this->source_height = ImageSY($this->gdimg_source);
-
- } else {
- $this->DebugMessage('ImageCreateFromStringReplacement() failed for "'.$MaskFilename.'"', __FILE__, __LINE__);
- }
-
- } else {
-
- if (phpthumb_functions::gd_version() >= 2) {
- $this->DebugMessage('Using non-alpha rotate because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
- } else {
- $this->DebugMessage('Using non-alpha rotate because $this->thumbnailFormat is "'.$this->thumbnailFormat.'"', __FILE__, __LINE__);
- }
-
- if (ImageColorTransparent($this->gdimg_source) >= 0) {
- // ImageRotate() forgets all about an image's transparency and sets the transparent color to black
- // To compensate, flood-fill the transparent color of the source image with the specified background color first
- // then rotate and the colors should match
-
- if (!function_exists('ImageIsTrueColor') || !ImageIsTrueColor($this->gdimg_source)) {
- // convert paletted image to true-color before rotating to prevent nasty aliasing artifacts
-
- $this->source_width = ImageSX($this->gdimg_source);
- $this->source_height = ImageSY($this->gdimg_source);
- $gdimg_newsrc = phpthumb_functions::ImageCreateFunction($this->source_width, $this->source_height);
- $background_color = phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $this->config_background_hexcolor);
- ImageFilledRectangle($gdimg_newsrc, 0, 0, $this->source_width, $this->source_height, phpthumb_functions::ImageHexColorAllocate($gdimg_newsrc, $this->config_background_hexcolor));
- ImageCopy($gdimg_newsrc, $this->gdimg_source, 0, 0, 0, 0, $this->source_width, $this->source_height);
- ImageDestroy($this->gdimg_source);
- unset($this->gdimg_source);
- $this->gdimg_source = $gdimg_newsrc;
- unset($gdimg_newsrc);
-
- } else {
-
- ImageColorSet(
- $this->gdimg_source,
- ImageColorTransparent($this->gdimg_source),
- hexdec(substr($this->config_background_hexcolor, 0, 2)),
- hexdec(substr($this->config_background_hexcolor, 2, 2)),
- hexdec(substr($this->config_background_hexcolor, 4, 2)));
-
- ImageColorTransparent($this->gdimg_source, -1);
-
- }
- }
-
- $this->gdimg_source = ImageRotate($this->gdimg_source, $rotate_angle, $background_color);
- $this->source_width = ImageSX($this->gdimg_source);
- $this->source_height = ImageSY($this->gdimg_source);
-
- }
- }
- }
- return true;
- }
-
-
- function FixedAspectRatio() {
- // optional fixed-dimension images (regardless of aspect ratio)
- if (isset($this->far)) {
- $this->is_alpha;
- if ($this->thumbnail_image_width >= $this->thumbnail_width) {
- if (isset($this->w)) {
- $aspectratio = $this->thumbnail_image_height / $this->thumbnail_image_width;
- $this->thumbnail_image_height = round($this->thumbnail_image_width * $aspectratio);
- if (!isset($this->h)) {
- $this->thumbnail_height = $this->thumbnail_image_height;
- }
- } elseif ($this->thumbnail_image_height < $this->thumbnail_height) {
- $this->thumbnail_image_height = $this->thumbnail_height;
- $this->thumbnail_image_width = round($this->thumbnail_image_height / $aspectratio);
- }
- } else {
- if (isset($this->h)) {
- $aspectratio = $this->thumbnail_image_width / $this->thumbnail_image_height;
- $this->thumbnail_image_width = round($this->thumbnail_image_height * $aspectratio);
- } elseif ($this->thumbnail_image_width < $this->thumbnail_width) {
- $this->thumbnail_image_width = $this->thumbnail_width;
- $this->thumbnail_image_height = round($this->thumbnail_image_width / $aspectratio);
- }
- }
- }
- return true;
- }
-
-
- function AntiOffsiteLinking() {
- // Optional anti-offsite hijacking of the thumbnail script
- $allow = true;
- if ($allow && $this->config_nooffsitelink_enabled && $this->config_nooffsitelink_require_refer) {
- $this->DebugMessage('AntiOffsiteLinking() checking $_SERVER[HTTP_REFERER] "'.@$_SERVER['HTTP_REFERER'].'"', __FILE__, __LINE__);
- $parsed_url = parse_url(@$_SERVER['HTTP_REFERER']);
- if (!in_array(@$parsed_url['host'], $this->config_nooffsitelink_valid_domains)) {
- $allow = false;
- $erase = $this->config_nooffsitelink_erase_image;
- $message = $this->config_nooffsitelink_text_message;
- $this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(';', $this->config_nooffsitelink_valid_domains).')', __FILE__, __LINE__);
- } else {
- $this->DebugMessage('AntiOffsiteLinking() - "'.@$parsed_url['host'].'" is in $this->config_nooffsitelink_valid_domains ('.implode(';', $this->config_nooffsitelink_valid_domains).')', __FILE__, __LINE__);
- }
- }
-
- if ($allow && $this->config_nohotlink_enabled && eregi('^(f|ht)tp[s]?://', $this->src)) {
- $parsed_url = parse_url($this->src);
- if (!in_array(@$parsed_url['host'], $this->config_nohotlink_valid_domains)) {
- // This domain is not allowed
- $allow = false;
- $erase = $this->config_nohotlink_erase_image;
- $message = $this->config_nohotlink_text_message;
- $this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is NOT in $this->config_nohotlink_valid_domains ('.implode(';', $this->config_nohotlink_valid_domains).')', __FILE__, __LINE__);
- } else {
- $this->DebugMessage('AntiOffsiteLinking() - "'.$parsed_url['host'].'" is in $this->config_nohotlink_valid_domains ('.implode(';', $this->config_nohotlink_valid_domains).')', __FILE__, __LINE__);
- }
- }
-
- if ($allow) {
- $this->DebugMessage('AntiOffsiteLinking() says this is allowed', __FILE__, __LINE__);
- return true;
- }
-
- if (!phpthumb_functions::IsHexColor($this->config_error_bgcolor)) {
- return $this->ErrorImage('Invalid hex color string "'.$this->config_error_bgcolor.'" for $this->config_error_bgcolor');
- }
- if (!phpthumb_functions::IsHexColor($this->config_error_textcolor)) {
- return $this->ErrorImage('Invalid hex color string "'.$this->config_error_textcolor.'" for $this->config_error_textcolor');
- }
- if ($erase) {
-
- return $this->ErrorImage($message, $this->thumbnail_width, $this->thumbnail_height, $this->config_error_bgcolor, $this->config_error_textcolor, $this->config_error_fontsize);
-
- } else {
-
- $nohotlink_text_array = explode("\n", wordwrap($message, floor($this->thumbnail_width / ImageFontWidth($this->config_error_fontsize)), "\n"));
- $nohotlink_text_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_output, $this->config_error_textcolor);
-
- $topoffset = round(($this->thumbnail_height - (count($nohotlink_text_array) * ImageFontHeight($this->config_error_fontsize))) / 2);
-
- $rowcounter = 0;
- $this->DebugMessage('AntiOffsiteLinking() writing '.count($nohotlink_text_array).' lines of text "'.$message.'" (in #'.$this->config_error_textcolor.') on top of image', __FILE__, __LINE__);
- foreach ($nohotlink_text_array as $textline) {
- $leftoffset = max(0, round(($this->thumbnail_width - (strlen($textline) * ImageFontWidth($this->config_error_fontsize))) / 2));
- ImageString($this->gdimg_output, $this->config_error_fontsize, $leftoffset, $topoffset + ($rowcounter++ * ImageFontHeight($this->config_error_fontsize)), $textline, $nohotlink_text_color);
- }
-
- }
- return true;
- }
-
-
- function AlphaChannelFlatten() {
- if (!$this->is_alpha) {
- // image doesn't have alpha transparency, no need to flatten
- $this->DebugMessage('skipping AlphaChannelFlatten() because !$this->is_alpha', __FILE__, __LINE__);
- return false;
- }
- if ($this->thumbnailFormat == 'png') {
-
- // image has alpha transparency, but output as PNG which can handle it
- $this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'")', __FILE__, __LINE__);
- return false;
-
- } elseif ($this->thumbnailFormat == 'gif') {
-
- // image has alpha transparency, but output as GIF which can handle only single-color transparency
- $CurrentImageColorTransparent = ImageColorTransparent($this->gdimg_output);
- if ($CurrentImageColorTransparent == -1) {
- // no transparent color defined
-
- if (phpthumb_functions::gd_version() < 2.0) {
- $this->DebugMessage('AlphaChannelFlatten() failed because GD version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
- return false;
- }
-
- if ($img_alpha_mixdown_dither = @ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output))) {
-
- for ($i = 0; $i <= 255; $i++) {
- $dither_color[$i] = ImageColorAllocate($img_alpha_mixdown_dither, $i, $i, $i);
- }
-
- // scan through current truecolor image copy alpha channel to temp image as grayscale
- for ($x = 0; $x < $this->thumbnail_width; $x++) {
- for ($y = 0; $y < $this->thumbnail_height; $y++) {
- $PixelColor = phpthumb_functions::GetPixelColor($this->gdimg_output, $x, $y);
- ImageSetPixel($img_alpha_mixdown_dither, $x, $y, $dither_color[($PixelColor['alpha'] * 2)]);
- }
- }
-
- // dither alpha channel grayscale version down to 2 colors
- ImageTrueColorToPalette($img_alpha_mixdown_dither, true, 2);
-
- // reduce color palette to 256-1 colors (leave one palette position for transparent color)
- ImageTrueColorToPalette($this->gdimg_output, true, 255);
-
- // allocate a new color for transparent color index
- $TransparentColor = ImageColorAllocate($this->gdimg_output, 1, 254, 253);
- ImageColorTransparent($this->gdimg_output, $TransparentColor);
-
- // scan through alpha channel image and note pixels with >50% transparency
- $TransparentPixels = array();
- for ($x = 0; $x < $this->thumbnail_width; $x++) {
- for ($y = 0; $y < $this->thumbnail_height; $y++) {
- $AlphaChannelPixel = phpthumb_functions::GetPixelColor($img_alpha_mixdown_dither, $x, $y);
- if ($AlphaChannelPixel['red'] > 127) {
- ImageSetPixel($this->gdimg_output, $x, $y, $TransparentColor);
- }
- }
- }
- ImageDestroy($img_alpha_mixdown_dither);
-
- $this->DebugMessage('AlphaChannelFlatten() set image to 255+1 colors with transparency for GIF output', __FILE__, __LINE__);
- return true;
-
- } else {
- $this->DebugMessage('AlphaChannelFlatten() failed ImageCreate('.ImageSX($this->gdimg_output).', '.ImageSY($this->gdimg_output).')', __FILE__, __LINE__);
- return false;
- }
-
- } else {
- // a single transparent color already defined, leave as-is
- $this->DebugMessage('skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.'") and ImageColorTransparent returned "'.$CurrentImageColorTransparent.'"', __FILE__, __LINE__);
- return true;
- }
-
- }
- $this->DebugMessage('continuing AlphaChannelFlatten() for output format "'.$this->thumbnailFormat.'"', __FILE__, __LINE__);
-
- // image has alpha transparency, and is being output in a format that doesn't support it -- flatten
- if ($gdimg_flatten_temp = phpthumb_functions::ImageCreateFunction($this->thumbnail_width, $this->thumbnail_height)) {
-
- $this->config_background_hexcolor = (!empty($this->bg) ? $this->bg : $this->config_background_hexcolor);
- if (!phpthumb_functions::IsHexColor($this->config_background_hexcolor)) {
- return $this->ErrorImage('Invalid hex color string "'.$this->config_background_hexcolor.'" for parameter "bg"');
- }
- $background_color = phpthumb_functions::ImageHexColorAllocate($this->gdimg_output, $this->config_background_hexcolor);
- ImageFilledRectangle($gdimg_flatten_temp, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $background_color);
- ImageCopy($gdimg_flatten_temp, $this->gdimg_output, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height);
-
- ImageAlphaBlending($this->gdimg_output, true);
- if (phpthumb_functions::version_compare_replacement(phpversion(), '4.3.2', '>=')) {
- ImageSaveAlpha($this->gdimg_output, false);
- }
- ImageColorTransparent($this->gdimg_output, -1);
- ImageCopy($this->gdimg_output, $gdimg_flatten_temp, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height);
-
- ImageDestroy($gdimg_flatten_temp);
- return true;
-
- } else {
- $this->DebugMessage('ImageCreateFunction() failed', __FILE__, __LINE__);
- }
- return false;
- }
-
-
- function ApplyFilters() {
- if (!empty($this->fltr) && is_array($this->fltr)) {
- if (!include_once(dirname(__FILE__).'/phpthumb.filters.php')) {
- $this->DebugMessage('Error including "'.dirname(__FILE__).'/phpthumb.filters.php" which is required for applying filters ('.implode(';', $this->fltr).')', __FILE__, __LINE__);
- return false;
- }
- foreach ($this->fltr as $filtercommand) {
- @list($command, $parameter) = explode('|', $filtercommand, 2);
- $this->DebugMessage('Attempting to process filter command "'.$command.'"', __FILE__, __LINE__);
- switch ($command) {
- case 'ds':
- phpthumb_filters::Desaturate($this->gdimg_output, $parameter, '');
- break;
-
- case 'gray':
- phpthumb_filters::Desaturate($this->gdimg_output, 100, '');
- break;
-
- case 'clr':
- if (phpthumb_functions::gd_version() < 2) {
- $this->DebugMessage('Skipping Colorize() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
- break;
- }
- @list($amount, $color) = explode('|', $parameter);
- phpthumb_filters::Colorize($this->gdimg_output, $amount, $color);
- break;
-
- case 'sep':
- if (phpthumb_functions::gd_version() < 2) {
- $this->DebugMessage('Skipping Sepia() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
- break;
- }
- @list($amount, $color) = explode('|', $parameter);
- phpthumb_filters::Sepia($this->gdimg_output, $amount, $color);
- break;
-
- case 'gam':
- phpthumb_filters::Gamma($this->gdimg_output, $parameter);
- break;
-
- case 'neg':
- phpthumb_filters::Negative($this->gdimg_output);
- break;
-
- case 'th':
- phpthumb_filters::Threshold($this->gdimg_output, $parameter);
- break;
-
- case 'flip':
- phpthumb_filters::Flip($this->gdimg_output, (strpos(strtolower($parameter), 'x') !== false), (strpos(strtolower($parameter), 'y') !== false));
- break;
-
- case 'bvl':
- @list($width, $color1, $color2) = explode('|', $parameter);
- phpthumb_filters::Bevel($this->gdimg_output, $width, $color1, $color2);
- break;
-
- case 'lvl':
- @list($band, $min, $max) = explode('|', $parameter);
- $band = ($band ? $band : '*');
- $min = ((strlen($min) > 0) ? $min : '-1');
- $max = ((strlen($max) > 0) ? $max : '-1');
- phpthumb_filters::HistogramStretch($this->gdimg_output, $band, $min, $max);
- break;
-
- case 'wb':
- phpthumb_filters::WhiteBalance($this->gdimg_output, $parameter);
- break;
-
- case 'hist':
- if (phpthumb_functions::gd_version() < 2) {
- $this->DebugMessage('Skipping HistogramOverlay() because gd_version is "'.phpthumb_functions::gd_version().'"', __FILE__, __LINE__);
- break;
- }
- @list($bands, $colors, $width, $height, $alignment, $opacity, $margin) = explode('|', $parameter);
- $bands = ($bands ? $bands : '*');
- $colors = ($colors ? $colors : '');
- $width = ($width ? $width : 0.25);
- $height = ($height ? $height : 0.25);
- $alignment = ($alignment ? $alignment : 'BR');
- $opacity = ($opacity ? $opacity : 50);
- $margin = ($margin ? $margin : 5);
- phpthumb_filters::HistogramOverlay($this->gdimg_output, $bands, $colors, $width, $height, $alignment, $opacity, $margin);
- break;
-
- case 'fram':
- @list($frame_width, $edge_width, $color_frame, $color1, $color2) = explode('|', $parameter);
- phpthumb_filters::Frame($this->gdimg_output, $frame_width, $edge_width, $co…
Large files files are truncated, but you can click here to view the full file