12 if (!include_once(dirname(__FILE__).
'/phpthumb.functions.php')) {
14 die(
'failed to include_once("'.realpath(dirname(__FILE__).
'/phpthumb.functions.php').
'")');
216 $this->
DebugMessage(
'phpThumb() v'.$this->phpthumb_version, __FILE__, __LINE__);
217 $this->config_max_source_pixels = round(max(intval(ini_get(
'memory_limit')), intval(get_cfg_var(
'memory_limit'))) * 1048576 * 0.20);
218 $this->iswindows = (bool) (strtoupper(substr(PHP_OS, 0, 3)) ==
'WIN');
219 $this->issafemode = (bool) preg_match(
'#(1|ON)#i', ini_get(
'safe_mode'));
221 $this->config_cache_prefix = ( isset(
$_SERVER[
'SERVER_NAME']) ?
$_SERVER[
'SERVER_NAME'].
'_' :
'');
225 $php_sapi_name = strtolower(function_exists(
'php_sapi_name') ? php_sapi_name() :
'');
226 if ($php_sapi_name ==
'cli') {
227 $this->config_allow_src_above_docroot =
true;
237 foreach ($this->tempFilesToDelete as $tempFileToDelete) {
238 if (file_exists($tempFileToDelete)) {
239 $this->
DebugMessage(
'Deleting temp file "'.$tempFileToDelete.
'"', __FILE__, __LINE__);
240 @unlink($tempFileToDelete);
243 $this->tempFilesToDelete = array();
253 if (is_null($this->config_output_format)) {
254 $sourceFileExtension = strtolower(substr(strrchr(
$sourceFilename,
'.'), 1));
255 if (preg_match(
'#^[a-z]{3,4}$#', $sourceFileExtension)) {
256 $this->config_output_format = $sourceFileExtension;
257 $this->
DebugMessage(
'setSourceFilename('.
$sourceFilename.
') set $this->config_output_format to "'.$sourceFileExtension.
'"', __FILE__, __LINE__);
259 $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__);
262 $this->
DebugMessage(
'setSourceFilename('.
$sourceFilename.
') set $this->sourceFilename to "'.$this->sourceFilename.
'"', __FILE__, __LINE__);
271 $this->
DebugMessage(
'setSourceData() setting $this->rawImageData ('.strlen($this->rawImageData).
' bytes; magic="'.substr($this->rawImageData, 0, 4).
'" ('.
phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)).
'))', __FILE__, __LINE__);
272 if ($this->config_cache_source_enabled) {
274 if (!is_dir($this->config_cache_source_directory)) {
275 $this->
ErrorImage(
'$this->config_cache_source_directory ('.$this->config_cache_source_directory.
') is not a directory');
276 } elseif (!@is_writable($this->config_cache_source_directory)) {
277 $this->
ErrorImage(
'$this->config_cache_source_directory ('.$this->config_cache_source_directory.
') is not writable');
279 $this->
DebugMessage(
'setSourceData() attempting to save source image to "'.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode(
$sourceFilename).
'"', __FILE__, __LINE__);
280 if ($fp = @fopen($this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode(
$sourceFilename),
'wb')) {
284 $this->
ErrorImage(
'setSourceData() failed to write to source cache ('.$this->config_cache_source_directory.DIRECTORY_SEPARATOR.urlencode(
$sourceFilename).
')');
293 $this->gdimg_source = $gdimg;
299 if ($param ==
'src') {
301 } elseif (@is_array($this->$param)) {
302 if (is_array($value)) {
303 foreach ($value as $arraykey => $arrayvalue) {
304 array_push($this->$param, $arrayvalue);
307 array_push($this->$param, $value);
310 $this->$param = $value;
318 return $this->$param;
336 if ($this->useRawIMoutput) {
337 $this->
DebugMessage(
'Skipping rest of GenerateThumbnail() because ($this->useRawIMoutput == true)', __FILE__, __LINE__);
342 $this->
DebugMessage(
'SourceImageToGD() failed', __FILE__, __LINE__);
351 switch ($this->far) {
355 $destination_offset_x = 0;
356 $destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
361 $destination_offset_x = round($this->thumbnail_width - $this->thumbnail_image_width);
362 $destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
367 $destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
368 $destination_offset_y = 0;
373 $destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
374 $destination_offset_y = round($this->thumbnail_height - $this->thumbnail_image_height);
378 $destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
379 $destination_offset_y = round(($this->thumbnail_height - $this->thumbnail_image_height) / 2);
399 $destination_offset_x,
400 $destination_offset_y,
401 $this->thumbnailCropX,
402 $this->thumbnailCropY,
403 $this->thumbnail_image_width,
404 $this->thumbnail_image_height,
405 $this->thumbnailCropW,
406 $this->thumbnailCropH
409 $this->
DebugMessage(
'memory_get_usage() after copy-resize = '.(function_exists(
'memory_get_usage') ? @memory_get_usage() :
'n/a'), __FILE__, __LINE__);
410 ImageDestroy($this->gdimg_source);
411 $this->
DebugMessage(
'memory_get_usage() after ImageDestroy = '.(function_exists(
'memory_get_usage') ? @memory_get_usage() :
'n/a'), __FILE__, __LINE__);
423 $this->
DebugMessage(
'GenerateThumbnail() completed successfully', __FILE__, __LINE__);
430 if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
431 $this->
DebugMessage(
'RenderOutput() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
434 if (!$this->thumbnailFormat) {
435 $this->
DebugMessage(
'RenderOutput() failed because $this->thumbnailFormat is empty', __FILE__, __LINE__);
438 if ($this->useRawIMoutput) {
439 $this->
DebugMessage(
'RenderOutput copying $this->IMresizedData ('.strlen($this->IMresizedData).
' bytes) to $this->outputImage', __FILE__, __LINE__);
444 $builtin_formats = array();
445 if (function_exists(
'ImageTypes')) {
446 $imagetypes = ImageTypes();
447 $builtin_formats[
'wbmp'] = (bool) ($imagetypes & IMG_WBMP);
448 $builtin_formats[
'jpg'] = (bool) ($imagetypes & IMG_JPG);
449 $builtin_formats[
'gif'] = (bool) ($imagetypes & IMG_GIF);
450 $builtin_formats[
'png'] = (bool) ($imagetypes & IMG_PNG);
452 $this->
DebugMessage(
'RenderOutput() attempting Image'.strtoupper(@$this->thumbnailFormat).
'($this->gdimg_output)', __FILE__, __LINE__);
454 switch ($this->thumbnailFormat) {
456 if (!@$builtin_formats[
'wbmp']) {
457 $this->
DebugMessage(
'GD does not have required built-in support for WBMP output', __FILE__, __LINE__);
461 ImageJPEG($this->gdimg_output, null, $this->thumbnailQuality);
462 $this->outputImageData = ob_get_contents();
467 if (!@$builtin_formats[
'jpg']) {
468 $this->
DebugMessage(
'GD does not have required built-in support for JPEG output', __FILE__, __LINE__);
472 ImageJPEG($this->gdimg_output, null, $this->thumbnailQuality);
473 $this->outputImageData = ob_get_contents();
477 if (!@$builtin_formats[
'png']) {
478 $this->
DebugMessage(
'GD does not have required built-in support for PNG output', __FILE__, __LINE__);
482 ImagePNG($this->gdimg_output);
483 $this->outputImageData = ob_get_contents();
487 if (!@$builtin_formats[
'gif']) {
488 $this->
DebugMessage(
'GD does not have required built-in support for GIF output', __FILE__, __LINE__);
492 ImageGIF($this->gdimg_output);
493 $this->outputImageData = ob_get_contents();
497 $ImageOutFunction =
'"builtin BMP output"';
498 if (!@include_once(dirname(__FILE__).
'/phpthumb.bmp.php')) {
499 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__);
504 $this->outputImageData = $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
505 unset($phpthumb_bmp);
509 $ImageOutFunction =
'"builtin ICO output"';
510 if (!@include_once(dirname(__FILE__).
'/phpthumb.ico.php')) {
511 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__);
516 $arrayOfOutputImages = array($this->gdimg_output);
517 $this->outputImageData = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
518 unset($phpthumb_ico);
522 $this->
DebugMessage(
'RenderOutput failed because $this->thumbnailFormat "'.$this->thumbnailFormat.
'" is not valid', __FILE__, __LINE__);
527 if (!$this->outputImageData) {
528 $this->
DebugMessage(
'RenderOutput() for "'.$this->thumbnailFormat.
'" failed', __FILE__, __LINE__);
532 $this->
DebugMessage(
'RenderOutput() completing with $this->outputImageData = '.strlen($this->outputImageData).
' bytes', __FILE__, __LINE__);
539 if (preg_match(
'#^(f|ht)tps?\://#i', $filename)) {
540 $this->
DebugMessage(
'RenderToFile() failed because $filename ('.$filename.
') is a URL', __FILE__, __LINE__);
545 $renderfilename = $filename;
546 if (($filename{0} !=
'/') && ($filename{0} !=
'\\') && ($filename{1} !=
':')) {
549 if (!@is_writable(dirname($renderfilename))) {
550 $this->
DebugMessage(
'RenderToFile() failed because "'.dirname($renderfilename).
'/" is not writable', __FILE__, __LINE__);
553 if (@is_file($renderfilename) && !@is_writable($renderfilename)) {
554 $this->
DebugMessage(
'RenderToFile() failed because "'.$renderfilename.
'" is not writable', __FILE__, __LINE__);
559 if (file_put_contents($renderfilename, $this->outputImageData)) {
560 $this->
DebugMessage(
'RenderToFile('.$renderfilename.
') succeeded', __FILE__, __LINE__);
563 if (!@file_exists($renderfilename)) {
564 $this->
DebugMessage(
'RenderOutput ['.$this->thumbnailFormat.
'('.$renderfilename.
')] did not appear to fail, but the output image does not exist either...', __FILE__, __LINE__);
567 $this->
DebugMessage(
'RenderOutput ['.$this->thumbnailFormat.
'('.$renderfilename.
')] failed', __FILE__, __LINE__);
577 if (!$this->useRawIMoutput && !is_resource($this->gdimg_output)) {
578 $this->
DebugMessage(
'OutputThumbnail() failed because !is_resource($this->gdimg_output)', __FILE__, __LINE__);
581 if (headers_sent()) {
582 return $this->
ErrorImage(
'OutputThumbnail() failed - headers already sent');
586 $downloadfilename =
phpthumb_functions::SanitizeFilename(is_string($this->sia) ? $this->sia : ($this->down ? $this->down :
'phpThumb_generated_thumbnail'.
'.'.$this->thumbnailFormat));
587 $this->
DebugMessage(
'Content-Disposition header filename set to "'.$downloadfilename.
'"', __FILE__, __LINE__);
588 if ($downloadfilename) {
589 header(
'Content-Disposition: '.($this->down ?
'attachment' :
'inline').
'; filename="'.$downloadfilename.
'"');
591 $this->
DebugMessage(
'failed to send Content-Disposition header because $downloadfilename is empty', __FILE__, __LINE__);
594 if ($this->useRawIMoutput) {
601 $this->
DebugMessage(
'ImageInterlace($this->gdimg_output, '.intval($this->config_output_interlace).
')', __FILE__, __LINE__);
602 ImageInterlace($this->gdimg_output, intval($this->config_output_interlace));
603 switch ($this->thumbnailFormat) {
606 $ImageOutFunction =
'image'.$this->thumbnailFormat;
607 @$ImageOutFunction($this->gdimg_output,
'', $this->thumbnailQuality);
613 $ImageOutFunction =
'image'.$this->thumbnailFormat;
614 @$ImageOutFunction($this->gdimg_output);
618 if (!@include_once(dirname(__FILE__).
'/phpthumb.bmp.php')) {
619 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.bmp.php" which is required for BMP format output', __FILE__, __LINE__);
623 if (is_object($phpthumb_bmp)) {
624 $bmp_data = $phpthumb_bmp->GD2BMPstring($this->gdimg_output);
625 unset($phpthumb_bmp);
627 $this->
DebugMessage(
'$phpthumb_bmp->GD2BMPstring() failed', __FILE__, __LINE__);
633 $this->
DebugMessage(
'new phpthumb_bmp() failed', __FILE__, __LINE__);
639 if (!@include_once(dirname(__FILE__).
'/phpthumb.ico.php')) {
640 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.ico.php" which is required for ICO format output', __FILE__, __LINE__);
644 if (is_object($phpthumb_ico)) {
645 $arrayOfOutputImages = array($this->gdimg_output);
646 $ico_data = $phpthumb_ico->GD2ICOstring($arrayOfOutputImages);
647 unset($phpthumb_ico);
649 $this->
DebugMessage(
'$phpthumb_ico->GD2ICOstring() failed', __FILE__, __LINE__);
655 $this->
DebugMessage(
'new phpthumb_ico() failed', __FILE__, __LINE__);
661 $this->
DebugMessage(
'OutputThumbnail failed because $this->thumbnailFormat "'.$this->thumbnailFormat.
'" is not valid', __FILE__, __LINE__);
673 $this->
DebugMessage(
'CleanUpCacheDirectory() set to purge ('.(is_null($this->config_cache_maxage) ?
'NULL' : number_format($this->config_cache_maxage / 86400, 1)).
' days; '.(is_null($this->config_cache_maxsize) ?
'NULL' : number_format($this->config_cache_maxsize / 1048576, 2)).
' MB; '.(is_null($this->config_cache_maxfiles) ?
'NULL' : number_format($this->config_cache_maxfiles)).
' files)', __FILE__, __LINE__);
675 if (!is_writable($this->config_cache_directory)) {
676 $this->
DebugMessage(
'CleanUpCacheDirectory() skipped because "'.$this->config_cache_directory.
'" is not writable', __FILE__, __LINE__);
681 $phpThumbCacheStats_filename = $this->config_cache_directory.DIRECTORY_SEPARATOR.
'phpThumbCacheStats.txt';
682 if (file_exists($phpThumbCacheStats_filename) && is_readable($phpThumbCacheStats_filename) && (filemtime($phpThumbCacheStats_filename) >= (time() - 3600))) {
683 $this->
DebugMessage(
'CleanUpCacheDirectory() skipped because "'.$phpThumbCacheStats_filename.
'" is recently modified', __FILE__, __LINE__);
686 touch($phpThumbCacheStats_filename);
688 $DeletedKeys = array();
689 $AllFilesInCacheDirectory = array();
690 if (($this->config_cache_maxage > 0) || ($this->config_cache_maxsize > 0) || ($this->config_cache_maxfiles > 0)) {
691 $CacheDirOldFilesAge = array();
692 $CacheDirOldFilesSize = array();
694 foreach ($AllFilesInCacheDirectory as $fullfilename) {
695 if (preg_match(
'#^'.preg_quote($this->config_cache_prefix).
'#i', $fullfilename) && file_exists($fullfilename)) {
696 $CacheDirOldFilesAge[$fullfilename] = @fileatime($fullfilename);
697 if ($CacheDirOldFilesAge[$fullfilename] == 0) {
698 $CacheDirOldFilesAge[$fullfilename] = @filemtime($fullfilename);
700 $CacheDirOldFilesSize[$fullfilename] = @filesize($fullfilename);
703 if (empty($CacheDirOldFilesSize)) {
706 $DeletedKeys[
'zerobyte'] = array();
707 foreach ($CacheDirOldFilesSize as $fullfilename => $filesize) {
709 $cutofftime = time() - 3600;
710 if (($filesize == 0) && ($CacheDirOldFilesAge[$fullfilename] < $cutofftime)) {
711 $this->
DebugMessage(
'deleting "'.$fullfilename.
'"', __FILE__, __LINE__);
712 if (@unlink($fullfilename)) {
713 $DeletedKeys[
'zerobyte'][] = $fullfilename;
714 unset($CacheDirOldFilesSize[$fullfilename]);
715 unset($CacheDirOldFilesAge[$fullfilename]);
719 $this->
DebugMessage(
'CleanUpCacheDirectory() purged '.count($DeletedKeys[
'zerobyte']).
' zero-byte files', __FILE__, __LINE__);
720 asort($CacheDirOldFilesAge);
722 if ($this->config_cache_maxfiles > 0) {
723 $TotalCachedFiles = count($CacheDirOldFilesAge);
724 $DeletedKeys[
'maxfiles'] = array();
725 foreach ($CacheDirOldFilesAge as $fullfilename => $filedate) {
726 if ($TotalCachedFiles > $this->config_cache_maxfiles) {
727 $this->
DebugMessage(
'deleting "'.$fullfilename.
'"', __FILE__, __LINE__);
728 if (@unlink($fullfilename)) {
730 $DeletedKeys[
'maxfiles'][] = $fullfilename;
737 $this->
DebugMessage(
'CleanUpCacheDirectory() purged '.count($DeletedKeys[
'maxfiles']).
' files based on (config_cache_maxfiles='.$this->config_cache_maxfiles.
')', __FILE__, __LINE__);
738 foreach ($DeletedKeys[
'maxfiles'] as $fullfilename) {
739 unset($CacheDirOldFilesAge[$fullfilename]);
740 unset($CacheDirOldFilesSize[$fullfilename]);
744 if ($this->config_cache_maxage > 0) {
746 $DeletedKeys[
'maxage'] = array();
747 foreach ($CacheDirOldFilesAge as $fullfilename => $filedate) {
749 if ($filedate < $mindate) {
750 $this->
DebugMessage(
'deleting "'.$fullfilename.
'"', __FILE__, __LINE__);
751 if (@unlink($fullfilename)) {
752 $DeletedKeys[
'maxage'][] = $fullfilename;
760 $this->
DebugMessage(
'CleanUpCacheDirectory() purged '.count($DeletedKeys[
'maxage']).
' files based on (config_cache_maxage='.$this->config_cache_maxage.
')', __FILE__, __LINE__);
761 foreach ($DeletedKeys[
'maxage'] as $fullfilename) {
762 unset($CacheDirOldFilesAge[$fullfilename]);
763 unset($CacheDirOldFilesSize[$fullfilename]);
767 if ($this->config_cache_maxsize > 0) {
768 $TotalCachedFileSize = array_sum($CacheDirOldFilesSize);
769 $DeletedKeys[
'maxsize'] = array();
770 foreach ($CacheDirOldFilesAge as $fullfilename => $filedate) {
771 if ($TotalCachedFileSize > $this->config_cache_maxsize) {
772 $this->
DebugMessage(
'deleting "'.$fullfilename.
'"', __FILE__, __LINE__);
773 if (@unlink($fullfilename)) {
774 $TotalCachedFileSize -= $CacheDirOldFilesSize[$fullfilename];
775 $DeletedKeys[
'maxsize'][] = $fullfilename;
782 $this->
DebugMessage(
'CleanUpCacheDirectory() purged '.count($DeletedKeys[
'maxsize']).
' files based on (config_cache_maxsize='.$this->config_cache_maxsize.
')', __FILE__, __LINE__);
783 foreach ($DeletedKeys[
'maxsize'] as $fullfilename) {
784 unset($CacheDirOldFilesAge[$fullfilename]);
785 unset($CacheDirOldFilesSize[$fullfilename]);
790 $this->
DebugMessage(
'skipping CleanUpCacheDirectory() because config set to not use it', __FILE__, __LINE__);
793 foreach ($DeletedKeys as $key => $value) {
794 $totalpurged += count($value);
796 $this->
DebugMessage(
'CleanUpCacheDirectory() purged '.$totalpurged.
' files (from '.count($AllFilesInCacheDirectory).
') based on config settings', __FILE__, __LINE__);
797 if ($totalpurged > 0) {
798 $empty_dirs = array();
799 foreach ($AllFilesInCacheDirectory as $fullfilename) {
800 if (is_dir($fullfilename)) {
801 $empty_dirs[realpath($fullfilename)] = 1;
803 unset($empty_dirs[realpath(dirname($fullfilename))]);
807 $totalpurgeddirs = 0;
808 foreach ($empty_dirs as $empty_dir => $dummy) {
809 if ($empty_dir == $this->config_cache_directory) {
812 } elseif (@rmdir($empty_dir)) {
815 $this->
DebugMessage(
'failed to rmdir('.$empty_dir.
')', __FILE__, __LINE__);
818 $this->
DebugMessage(
'purged '.$totalpurgeddirs.
' empty directories', __FILE__, __LINE__);
827 $class_vars = get_class_vars(get_class($this));
828 foreach ($class_vars as $key => $value) {
830 if (!preg_match(
'#^(config_|debug|fatalerror)#i', $key)) {
831 $this->$key = $value;
841 if (is_resource($this->gdimg_source)) {
842 $this->
DebugMessage(
'ResolveSource() exiting because is_resource($this->gdimg_source)', __FILE__, __LINE__);
845 if ($this->rawImageData) {
846 $this->sourceFilename = null;
847 $this->
DebugMessage(
'ResolveSource() exiting because $this->rawImageData is set ('.number_format(strlen($this->rawImageData)).
' bytes)', __FILE__, __LINE__);
850 if ($this->sourceFilename) {
852 $this->
DebugMessage(
'$this->sourceFilename set to "'.$this->sourceFilename.
'"', __FILE__, __LINE__);
853 } elseif ($this->src) {
855 $this->
DebugMessage(
'$this->sourceFilename set to "'.$this->sourceFilename.
'" from $this->src ('.$this->src.
')', __FILE__, __LINE__);
857 return $this->
ErrorImage(
'$this->sourceFilename and $this->src are both empty');
859 if ($this->iswindows && ((substr($this->sourceFilename, 0, 2) ==
'//') || (substr($this->sourceFilename, 0, 2) ==
'\\\\'))) {
861 } elseif (preg_match(
'#^(f|ht)tps?\://#i', $this->sourceFilename)) {
863 if ($this->config_http_user_agent) {
864 ini_set(
'user_agent', $this->config_http_user_agent);
866 } elseif (!@file_exists($this->sourceFilename)) {
867 return $this->
ErrorImage(
'"'.$this->sourceFilename.
'" does not exist');
868 } elseif (!@is_file($this->sourceFilename)) {
869 return $this->
ErrorImage(
'"'.$this->sourceFilename.
'" is not a file');
875 static $alreadyCalled =
false;
876 if ($this->thumbnailFormat && $alreadyCalled) {
879 $alreadyCalled =
true;
881 $AvailableImageOutputFormats = array();
882 $AvailableImageOutputFormats[] =
'text';
883 if (@is_readable(dirname(__FILE__).
'/phpthumb.ico.php')) {
884 $AvailableImageOutputFormats[] =
'ico';
886 if (@is_readable(dirname(__FILE__).
'/phpthumb.bmp.php')) {
887 $AvailableImageOutputFormats[] =
'bmp';
890 $this->thumbnailFormat =
'ico';
893 if (function_exists(
'ImageTypes')) {
894 $imagetypes = ImageTypes();
895 if ($imagetypes & IMG_WBMP) {
896 $this->thumbnailFormat =
'wbmp';
897 $AvailableImageOutputFormats[] =
'wbmp';
899 if ($imagetypes & IMG_GIF) {
900 $this->thumbnailFormat =
'gif';
901 $AvailableImageOutputFormats[] =
'gif';
903 if ($imagetypes & IMG_PNG) {
904 $this->thumbnailFormat =
'png';
905 $AvailableImageOutputFormats[] =
'png';
907 if ($imagetypes & IMG_JPG) {
908 $this->thumbnailFormat =
'jpeg';
909 $AvailableImageOutputFormats[] =
'jpeg';
913 $this->
DebugMessage(
'ImageTypes() does not exist - GD support might not be enabled?', __FILE__, __LINE__);
916 $IMformats = array(
'jpeg',
'png',
'gif',
'bmp',
'ico',
'wbmp');
917 $this->
DebugMessage(
'Addding ImageMagick formats to $AvailableImageOutputFormats ('.implode(
';', $AvailableImageOutputFormats).
')', __FILE__, __LINE__);
918 foreach ($IMformats as $key => $format) {
919 $AvailableImageOutputFormats[] = $format;
922 $AvailableImageOutputFormats = array_unique($AvailableImageOutputFormats);
923 $this->
DebugMessage(
'$AvailableImageOutputFormats = array('.implode(
';', $AvailableImageOutputFormats).
')', __FILE__, __LINE__);
925 $this->f = preg_replace(
'#[^a-z]#',
'', strtolower($this->f));
926 if (strtolower($this->config_output_format) ==
'jpg') {
927 $this->config_output_format =
'jpeg';
929 if (strtolower($this->f) ==
'jpg') {
934 $this->
DebugMessage(
'$this->thumbnailFormat set to $this->config_output_format "'.strtolower($this->config_output_format).
'"', __FILE__, __LINE__);
935 $this->thumbnailFormat = strtolower($this->config_output_format);
936 } elseif ($this->config_output_format) {
937 $this->
DebugMessage(
'$this->thumbnailFormat staying as "'.$this->thumbnailFormat.
'" because $this->config_output_format ('.strtolower($this->config_output_format).
') is not in $AvailableImageOutputFormats', __FILE__, __LINE__);
941 $this->
DebugMessage(
'$this->thumbnailFormat set to $this->f "'.strtolower($this->f).
'"', __FILE__, __LINE__);
942 $this->thumbnailFormat = strtolower($this->f);
943 } elseif ($this->f) {
944 $this->
DebugMessage(
'$this->thumbnailFormat staying as "'.$this->thumbnailFormat.
'" because $this->f ('.strtolower($this->f).
') is not in $AvailableImageOutputFormats', __FILE__, __LINE__);
950 $this->thumbnailQuality = max(1, min(99, ($this->q ? intval($this->q) : 75)));
951 $this->
DebugMessage(
'$this->thumbnailQuality set to "'.$this->thumbnailQuality.
'"', __FILE__, __LINE__);
958 $this->
DebugMessage(
'setCacheDirectory() starting with config_cache_directory = "'.$this->config_cache_directory.
'"', __FILE__, __LINE__);
959 if (substr($this->config_cache_directory, 0, 1) ==
'.') {
960 if (preg_match(
'#^(f|ht)tps?\://#i', $this->src)) {
961 if (!$this->config_cache_disable_warning) {
962 $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');
964 } elseif ($this->src) {
966 $this->config_cache_directory = dirname($this->
ResolveFilenameToAbsolute($this->src)).DIRECTORY_SEPARATOR.$this->config_cache_directory;
971 if (substr($this->config_cache_directory, -1) ==
'/') {
972 $this->config_cache_directory = substr($this->config_cache_directory, 0, -1);
974 if ($this->iswindows) {
975 $this->config_cache_directory = str_replace(
'/',
DIRECTORY_SEPARATOR, $this->config_cache_directory);
977 if ($this->config_cache_directory) {
978 $real_cache_path = realpath($this->config_cache_directory);
979 if (!$real_cache_path) {
980 $this->
DebugMessage(
'realpath($this->config_cache_directory) failed for "'.$this->config_cache_directory.
'"', __FILE__, __LINE__);
981 if (!is_dir($this->config_cache_directory)) {
982 $this->
DebugMessage(
'!is_dir('.$this->config_cache_directory.
')', __FILE__, __LINE__);
985 if ($real_cache_path) {
986 $this->
DebugMessage(
'setting config_cache_directory to realpath('.$this->config_cache_directory.
') = "'.$real_cache_path.
'"', __FILE__, __LINE__);
987 $this->config_cache_directory = $real_cache_path;
990 if (!is_dir($this->config_cache_directory)) {
991 if (!$this->config_cache_disable_warning) {
992 $this->
ErrorImage(
'$this->config_cache_directory ('.$this->config_cache_directory.
') does not exist. Adjust "cache_directory" or "cache_disable_warning" in phpThumb.config.php');
994 $this->
DebugMessage(
'$this->config_cache_directory ('.$this->config_cache_directory.
') is not a directory', __FILE__, __LINE__);
995 $this->config_cache_directory = null;
996 } elseif (!@is_writable($this->config_cache_directory)) {
997 $this->
DebugMessage(
'$this->config_cache_directory is not writable ('.$this->config_cache_directory.
')', __FILE__, __LINE__);
1001 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)) {
1002 $this->
DebugMessage(
'setting $this->config_temp_directory = $this->config_cache_directory ('.$this->config_cache_directory.
')', __FILE__, __LINE__);
1010 if (empty($filename)) {
1014 if (preg_match(
'#^[a-z0-9]+\:/{1,2}#i', $filename)) {
1022 } elseif ($this->iswindows && isset($filename{1}) && ($filename{1} ==
':')) {
1025 $AbsoluteFilename = $filename;
1027 } elseif ($this->iswindows && ((substr($filename, 0, 2) ==
'//') || (substr($filename, 0, 2) ==
'\\\\'))) {
1030 $AbsoluteFilename = $filename;
1032 } elseif ($filename{0} ==
'/') {
1034 if (@is_readable($filename) && !@is_readable($this->config_document_root.$filename)) {
1037 $AbsoluteFilename = $filename;
1039 } elseif (isset($filename{1}) && ($filename{1} ==
'~')) {
1043 $AbsoluteFilename = $ApacheLookupURIarray[
'filename'];
1045 $AbsoluteFilename = realpath($filename);
1046 if (@is_readable($AbsoluteFilename)) {
1047 $this->
DebugMessage(
'phpthumb_functions::ApacheLookupURIarray() failed for "'.$filename.
'", but the correct filename ('.$AbsoluteFilename.
') seems to have been resolved with realpath($filename)', __FILE__, __LINE__);
1048 } elseif (is_dir(dirname($AbsoluteFilename))) {
1049 $this->
DebugMessage(
'phpthumb_functions::ApacheLookupURIarray() failed for "'.dirname($filename).
'", but the correct directory ('.dirname($AbsoluteFilename).
') seems to have been resolved with realpath(.)', __FILE__, __LINE__);
1051 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")');
1058 if (preg_match(
'#^'.preg_quote($this->config_document_root).
'#', $filename)) {
1059 $AbsoluteFilename = $filename;
1060 $this->
DebugMessage(
'ResolveFilenameToAbsolute() NOT prepending $this->config_document_root ('.$this->config_document_root.
') to $filename ('.$filename.
') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.
'")', __FILE__, __LINE__);
1062 $AbsoluteFilename = $this->config_document_root.$filename;
1063 $this->
DebugMessage(
'ResolveFilenameToAbsolute() prepending $this->config_document_root ('.$this->config_document_root.
') to $filename ('.$filename.
') resulting in ($AbsoluteFilename = "'.$AbsoluteFilename.
'")', __FILE__, __LINE__);
1072 $AbsoluteFilename = dirname(__FILE__).DIRECTORY_SEPARATOR.preg_replace(
'#[/\\\\]#',
DIRECTORY_SEPARATOR, $filename);
1078 if (substr(dirname(@
$_SERVER[
'PHP_SELF']), 0, 2) ==
'/~') {
1080 $AbsoluteFilename = $ApacheLookupURIarray[
'filename'].DIRECTORY_SEPARATOR.$filename;
1082 $AbsoluteFilename = realpath(
'.').DIRECTORY_SEPARATOR.$filename;
1083 if (@is_readable($AbsoluteFilename)) {
1084 $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__);
1085 } elseif (is_dir(dirname($AbsoluteFilename))) {
1086 $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__);
1088 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');
1094 if (is_link($AbsoluteFilename)) {
1095 $this->
DebugMessage(
'is_link()==true, changing "'.$AbsoluteFilename.
'" to "'.readlink($AbsoluteFilename).
'"', __FILE__, __LINE__);
1096 $AbsoluteFilename = readlink($AbsoluteFilename);
1098 if (realpath($AbsoluteFilename)) {
1099 $AbsoluteFilename = realpath($AbsoluteFilename);
1101 if ($this->iswindows) {
1102 $AbsoluteFilename = preg_replace(
'#^'.preg_quote(realpath($this->config_document_root)).
'#i', realpath($this->config_document_root), $AbsoluteFilename);
1105 if (!$this->config_allow_src_above_docroot && !preg_match(
'#^'.preg_quote(str_replace(
DIRECTORY_SEPARATOR,
'/', realpath($this->config_document_root))).
'#', $AbsoluteFilename)) {
1106 $this->
DebugMessage(
'!$this->config_allow_src_above_docroot therefore setting "'.$AbsoluteFilename.
'" (outside "'.realpath($this->config_document_root).
'") to null', __FILE__, __LINE__);
1109 if (!$this->config_allow_src_above_phpthumb && !preg_match(
'#^'.preg_quote(str_replace(
DIRECTORY_SEPARATOR,
'/', dirname(__FILE__))).
'#', $AbsoluteFilename)) {
1110 $this->
DebugMessage(
'!$this->config_allow_src_above_phpthumb therefore setting "'.$AbsoluteFilename.
'" (outside "'.dirname(__FILE__).
'") to null', __FILE__, __LINE__);
1113 return $AbsoluteFilename;
1117 static $open_basedirs = null;
1118 static $file_exists_cache = array();
1119 if (!$cached || !isset($file_exists_cache[$filename])) {
1120 if (is_null($open_basedirs)) {
1121 $open_basedirs = explode(
';', ini_get(
'open_basedir'));
1123 if (empty($open_basedirs) || in_array(dirname($filename), $open_basedirs)) {
1124 $file_exists_cache[$filename] = file_exists($filename);
1125 } elseif ($this->iswindows) {
1127 $file_exists_cache[$filename] = !preg_match(
'#File Not Found#i', $ls_filename);
1130 $file_exists_cache[$filename] = ($ls_filename == $filename);
1133 return $file_exists_cache[$filename];
1137 static $WhichConvert = null;
1138 if (is_null($WhichConvert)) {
1139 if ($this->iswindows) {
1140 $WhichConvert =
false;
1145 return $WhichConvert;
1149 static $commandline = null;
1150 if (is_null($commandline)) {
1151 if ($this->issafemode) {
1153 return $commandline;
1155 $commandline = (!is_null($this->config_imagemagick_path) ? $this->config_imagemagick_path :
'');
1157 if ($this->config_imagemagick_path && ($this->config_imagemagick_path != realpath($this->config_imagemagick_path))) {
1158 if (@is_executable(realpath($this->config_imagemagick_path))) {
1159 $this->
DebugMessage(
'Changing $this->config_imagemagick_path ('.$this->config_imagemagick_path.
') to realpath($this->config_imagemagick_path) ('.realpath($this->config_imagemagick_path).
')', __FILE__, __LINE__);
1160 $this->config_imagemagick_path = realpath($this->config_imagemagick_path);
1162 $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__);
1165 $this->
DebugMessage(
' file_exists('.$this->config_imagemagick_path.
') = '.intval( @file_exists($this->config_imagemagick_path)), __FILE__, __LINE__);
1167 $this->
DebugMessage(
' is_file('.$this->config_imagemagick_path.
') = '.intval( @is_file($this->config_imagemagick_path)), __FILE__, __LINE__);
1168 $this->
DebugMessage(
' is_executable('.$this->config_imagemagick_path.
') = '.intval( @is_executable($this->config_imagemagick_path)), __FILE__, __LINE__);
1171 $this->
DebugMessage(
'using ImageMagick path from $this->config_imagemagick_path ('.$this->config_imagemagick_path.
')', __FILE__, __LINE__);
1172 if ($this->iswindows) {
1173 $commandline = substr($this->config_imagemagick_path, 0, 2).
' && cd '.escapeshellarg(str_replace(
'/',
DIRECTORY_SEPARATOR, substr(dirname($this->config_imagemagick_path), 2))).
' && '.escapeshellarg(basename($this->config_imagemagick_path));
1175 $commandline = escapeshellarg($this->config_imagemagick_path);
1177 return $commandline;
1188 $this->
DebugMessage(
'using ImageMagick path from `which convert` ('.$which_convert.
')', __FILE__, __LINE__);
1189 $commandline =
'convert';
1191 } elseif ($IMversion) {
1193 $this->
DebugMessage(
'setting ImageMagick path to $this->config_imagemagick_path ('.$this->config_imagemagick_path.
') ['.$IMversion.
']', __FILE__, __LINE__);
1198 $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__);
1203 return $commandline;
1207 static $versionstring = null;
1208 if (is_null($versionstring)) {
1209 $versionstring = array(0=>
false, 1=>
false);
1211 $commandline = (!is_null($commandline) ? $commandline :
'');
1214 $commandline .=
' --version';
1215 $this->
DebugMessage(
'ImageMagick version checked with "'.$commandline.
'"', __FILE__, __LINE__);
1217 if (preg_match(
'#^Version: [^0-9]*([ 0-9\\.\\:Q/\\-]+) (http|file)\:#i', $versionstring[1], $matches)) {
1218 $versionstring[0] = $matches[1];
1220 $versionstring[0] =
false;
1221 $this->
DebugMessage(
'ImageMagick did not return recognized version string ('.$versionstring[1].
')', __FILE__, __LINE__);
1223 $this->
DebugMessage(
'ImageMagick convert --version says "'.@$matches[0].
'"', __FILE__, __LINE__);
1226 return $versionstring[intval($returnRAW)];
1230 static $IMoptions = null;
1231 if (is_null($IMoptions)) {
1232 $IMoptions = array();
1234 if (!is_null($commandline)) {
1235 $commandline .=
' -help';
1237 foreach ($IMhelp_lines as $line) {
1238 if (preg_match(
'#^[\\+\\-]([a-z\\-]+) #', trim($line), $matches)) {
1239 $IMoptions[$matches[1]] =
true;
1244 if (is_array($switchname)) {
1246 foreach ($switchname as $key => $value) {
1247 if (!isset($IMoptions[$value])) {
1252 $this->
DebugMessage(
'ImageMagickSwitchAvailable('.implode(
';', $switchname).
') = '.intval($allOK).
'', __FILE__, __LINE__);
1254 $allOK = isset($IMoptions[$switchname]);
1255 $this->
DebugMessage(
'ImageMagickSwitchAvailable('.$switchname.
') = '.intval($allOK).
'', __FILE__, __LINE__);
1261 static $IMformatsList = null;
1262 if (is_null($IMformatsList)) {
1263 $IMformatsList =
'';
1265 if (!is_null($commandline)) {
1266 $commandline = dirname($commandline).DIRECTORY_SEPARATOR.str_replace(
'convert',
'identify', basename($commandline));
1267 $commandline .=
' -list format';
1271 return $IMformatsList;
1276 $IMtempSourceFilename = realpath($IMtempSourceFilename);
1278 $fp_tempfile = fopen($IMtempSourceFilename,
'wb');
1279 $tempfile_open_error = ob_get_contents();
1282 fwrite($fp_tempfile, $this->rawImageData);
1283 fclose($fp_tempfile);
1284 $this->sourceFilename = $IMtempSourceFilename;
1285 $this->
DebugMessage(
'ImageMagickThumbnailToGD() setting $this->sourceFilename to "'.$IMtempSourceFilename.
'" from $this->rawImageData ('.strlen($this->rawImageData).
' bytes)', __FILE__, __LINE__);
1287 $this->
DebugMessage(
'ImageMagickThumbnailToGD() FAILED setting $this->sourceFilename to "'.$IMtempSourceFilename.
'" (failed to open for writing: "'.$tempfile_open_error.
'")', __FILE__, __LINE__);
1289 unset($tempfile_open_error, $IMtempSourceFilename);
1292 $this->
DebugMessage(
'SourceDataToTempFile() FAILED because $this->phpThumb_tempnam() failed', __FILE__, __LINE__);
1299 $this->useRawIMoutput =
true;
1305 $UnAllowedParameters = array(
'xto',
'ar',
'bg',
'bc');
1307 foreach ($UnAllowedParameters as $parameter) {
1308 if (isset($this->$parameter)) {
1309 $this->
DebugMessage(
'$this->useRawIMoutput=false because "'.$parameter.
'" is set', __FILE__, __LINE__);
1310 $this->useRawIMoutput =
false;
1315 $this->
DebugMessage(
'$this->useRawIMoutput='.($this->useRawIMoutput ?
'true' :
'false').
' after checking $UnAllowedParameters', __FILE__, __LINE__);
1318 if ($this->useRawIMoutput) {
1319 switch ($this->thumbnailFormat) {
1321 $ImageCreateFunction =
'ImageCreateFromGIF';
1322 $this->is_alpha =
true;
1325 $ImageCreateFunction =
'ImageCreateFromPNG';
1326 $this->is_alpha =
true;
1330 $ImageCreateFunction =
'ImageCreateFromJPEG';
1333 $this->
DebugMessage(
'Forcing output to PNG because $this->thumbnailFormat ('.$this->thumbnailFormat.
' is not a GD-supported format)', __FILE__, __LINE__);
1334 $outputFormat =
'png';
1335 $ImageCreateFunction =
'ImageCreateFromPNG';
1336 $this->is_alpha =
true;
1337 $this->useRawIMoutput =
false;
1340 if (!function_exists(@$ImageCreateFunction)) {
1343 $this->useRawIMoutput =
true;
1347 $outputFormat =
'png';
1348 $ImageCreateFunction =
'ImageCreateFromPNG';
1349 $this->is_alpha =
true;
1350 $this->useRawIMoutput =
false;
1355 if (!$this->sourceFilename && $this->rawImageData) {
1358 if (!$this->sourceFilename) {
1359 $this->
DebugMessage(
'ImageMagickThumbnailToGD() aborting because $this->sourceFilename is empty', __FILE__, __LINE__);
1360 $this->useRawIMoutput =
false;
1363 if ($this->issafemode) {
1364 $this->
DebugMessage(
'ImageMagickThumbnailToGD() aborting because safe_mode is enabled', __FILE__, __LINE__);
1365 $this->useRawIMoutput =
false;
1378 $IMtempfilename = realpath($IMtempfilename);
1380 $IMuseExplicitImageOutputDimensions =
false;
1382 $IMresizeParameter =
'thumbnail';
1384 $IMresizeParameter =
'resize';
1389 $IMuseExplicitImageOutputDimensions = preg_match(
'#image dimensions are zero#i', $IMresult_test);
1390 $this->
DebugMessage(
'IMuseExplicitImageOutputDimensions = '.intval($IMuseExplicitImageOutputDimensions), __FILE__, __LINE__);
1391 if ($fp_im_temp = @fopen($IMtempfilename,
'wb')) {
1393 fclose($fp_im_temp);
1400 $commandline .=
' -density '.escapeshellarg($this->dpi);
1403 $getimagesize = GetImageSize($this->sourceFilename);
1404 $GetImageSizeError = ob_get_contents();
1406 if (is_array($getimagesize)) {
1407 $this->
DebugMessage(
'GetImageSize('.$this->sourceFilename.
') SUCCEEDED: '.print_r($getimagesize,
true), __FILE__, __LINE__);
1409 $this->
DebugMessage(
'GetImageSize('.$this->sourceFilename.
') FAILED with error "'.$GetImageSizeError.
'"', __FILE__, __LINE__);
1411 if (is_array($getimagesize)) {
1412 $this->
DebugMessage(
'GetImageSize('.$this->sourceFilename.
') returned [w='.$getimagesize[0].
';h='.$getimagesize[1].
';f='.$getimagesize[2].
']', __FILE__, __LINE__);
1413 $this->source_width = $getimagesize[0];
1414 $this->source_height = $getimagesize[1];
1415 $this->
DebugMessage(
'source dimensions set to '.$this->source_width.
'x'.$this->source_height, __FILE__, __LINE__);
1418 if (!preg_match(
'#('.implode(
'|', $this->AlphaCapableFormats).
')#i', $outputFormat)) {
1420 $commandline .=
' -background '.escapeshellarg(
'#'.($this->bg ? $this->bg :
'FFFFFF'));
1421 if ($getimagesize[2] == IMAGETYPE_GIF) {
1422 $commandline .=
' -flatten';
1425 if ($getimagesize[2] == IMAGETYPE_GIF) {
1426 $commandline .=
' -coalesce';
1428 if ($this->source_width || $this->source_height) {
1431 $borderThickness = 0;
1432 if (!empty($this->fltr)) {
1433 foreach ($this->fltr as $key => $value) {
1434 if (preg_match(
'#^bord\|([0-9]+)#', $value, $matches)) {
1435 $borderThickness = $matches[1];
1440 $wAll = intval(max($this->w, $this->wp, $this->wl, $this->ws)) - (2 * $borderThickness);
1441 $hAll = intval(max($this->h, $this->hp, $this->hl, $this->hs)) - (2 * $borderThickness);
1443 $zcAR = (($wAll && $hAll) ? $wAll / $hAll : 1);
1448 $thumbnailH = round(max($sideY, ($sideY * $zcAR) / $imAR));
1449 $commandline .=
' -'.$IMresizeParameter.
' '.escapeshellarg(($IMuseExplicitImageOutputDimensions ? $thumbnailH :
'').
'x'.$thumbnailH);
1451 switch (strtoupper($this->zc)) {
1453 $commandline .=
' -gravity north';
1456 $commandline .=
' -gravity south';
1459 $commandline .=
' -gravity west';
1462 $commandline .=
' -gravity east';
1465 $commandline .=
' -gravity northwest';
1468 $commandline .=
' -gravity northeast';
1471 $commandline .=
' -gravity southwest';
1474 $commandline .=
' -gravity southeast';
1479 $commandline .=
' -gravity center';
1483 if (($wAll > 0) && ($hAll > 0)) {
1484 $commandline .=
' -crop '.escapeshellarg($wAll.
'x'.$hAll.
'+0+0');
1486 $commandline .=
' -crop '.escapeshellarg($side.
'x'.$side.
'+0+0');
1489 $commandline .=
' +repage';
1494 } elseif ($this->sw || $this->sh || $this->sx || $this->sy) {
1497 $crop_param .= ($this->sw ? (($this->sw < 2) ? round($this->sw * $this->source_width) :
$this->sw) : $this->source_width);
1498 $crop_param .=
'x'.($this->sh ? (($this->sh < 2) ? round($this->sh * $this->source_height) :
$this->sh) : $this->source_height);
1499 $crop_param .=
'+'.(($this->sx < 2) ? round($this->sx * $this->source_width) :
$this->sx);
1500 $crop_param .=
'+'.(($this->sy < 2) ? round($this->sy * $this->source_height) :
$this->sy);
1508 if ($this->w || $this->h) {
1513 $commandline .=
' -repage';
1517 if ($IMuseExplicitImageOutputDimensions) {
1518 if ($this->w && !$this->h) {
1519 $this->h = ceil($this->w / ($this->source_width / $this->source_height));
1520 } elseif ($this->h && !$this->w) {
1521 $this->w = ceil($this->h * ($this->source_width / $this->source_height));
1524 $commandline .=
' -'.$IMresizeParameter.
' '.escapeshellarg($this->w.
'x'.$this->h);
1529 if ($this->iar && (intval($this->w) > 0) && (intval($this->h) > 0)) {
1531 $nw = ((round($nw) != 0) ? round($nw) :
'');
1532 $nh = ((round($nh) != 0) ? round($nh) :
'');
1533 $commandline .=
' -'.$IMresizeParameter.
' '.escapeshellarg($nw.
'x'.$nh.
'!');
1537 if ($this->w || $this->h) {
1538 if ($IMuseExplicitImageOutputDimensions) {
1539 if ($this->w && !$this->h) {
1540 $this->h = ceil($this->w / ($this->source_width / $this->source_height));
1541 } elseif ($this->h && !$this->w) {
1542 $this->w = ceil($this->h * ($this->source_width / $this->source_height));
1546 $nw = ((round($nw) != 0) ? round($nw) :
'');
1547 $nh = ((round($nh) != 0) ? round($nh) :
'');
1548 $commandline .=
' -'.$IMresizeParameter.
' '.escapeshellarg($nw.
'x'.$nh);
1556 $this->
DebugMessage(
'GetImageSize('.$this->sourceFilename.
') failed', __FILE__, __LINE__);
1557 if ($this->w || $this->h) {
1558 $exactDimensionsBang = (($this->iar && (intval($this->w) > 0) && (intval($this->h) > 0)) ?
'!' :
'');
1559 if ($IMuseExplicitImageOutputDimensions) {
1561 $commandline .=
' -'.$IMresizeParameter.
' '.escapeshellarg(($this->w ? $this->w :
'9999').
'x'.($this->h ? $this->h :
'9999').$exactDimensionsBang);
1563 $commandline .=
' -'.$IMresizeParameter.
' '.escapeshellarg($this->w.
'x'.$this->h.$exactDimensionsBang);
1570 $this->ra = intval($this->ra);
1573 $this->
DebugMessage(
'Using ImageMagick rotate', __FILE__, __LINE__);
1574 $commandline .=
' -rotate '.escapeshellarg($this->ra);
1575 if (($this->ra % 90) != 0) {
1576 if (preg_match(
'#('.implode(
'|', $this->AlphaCapableFormats).
')#i', $outputFormat)) {
1578 $commandline .=
' -background rgba(255,255,255,0)';
1580 $commandline .=
' -background '.escapeshellarg(
'#'.($this->bg ? $this->bg :
'FFFFFF'));
1585 $this->
DebugMessage(
'Not using ImageMagick rotate because alpha background buggy before v6.3.7', __FILE__, __LINE__);
1588 $this->
DebugMessage(
'Not using ImageMagick rotate because not supported', __FILE__, __LINE__);
1592 $successfullyProcessedFilters = array();
1593 foreach ($this->fltr as $filterkey => $filtercommand) {
1594 @list($command, $parameter) = explode(
'|', $filtercommand, 2);
1598 $commandline .=
' -modulate '.escapeshellarg((100 + intval($parameter)).
',100,100');
1599 $successfullyProcessedFilters[] = $filterkey;
1605 $contDiv10 = round(intval($parameter) / 10);
1606 if ($contDiv10 > 0) {
1607 $contDiv10 = min($contDiv10, 100);
1608 for (
$i = 0;
$i < $contDiv10;
$i++) {
1609 $commandline .=
' -contrast';
1611 } elseif ($contDiv10 < 0) {
1612 $contDiv10 = max($contDiv10, -100);
1613 for (
$i = $contDiv10;
$i < 0;
$i++) {
1614 $commandline .=
' +contrast';
1619 $successfullyProcessedFilters[] = $filterkey;
1625 if ($parameter == 100) {
1626 $commandline .=
' -colorspace GRAY';
1627 $commandline .=
' -modulate 100,0,100';
1629 $commandline .=
' -modulate '.escapeshellarg(
'100,'.(100 - intval($parameter)).
',100');
1631 $successfullyProcessedFilters[] = $filterkey;
1637 if ($parameter == -100) {
1638 $commandline .=
' -colorspace GRAY';
1639 $commandline .=
' -modulate 100,0,100';
1641 $commandline .=
' -modulate '.escapeshellarg(
'100,'.(100 + intval($parameter)).
',100');
1643 $successfullyProcessedFilters[] = $filterkey;
1649 $commandline .=
' -colorspace GRAY';
1650 $commandline .=
' -modulate 100,0,100';
1651 $successfullyProcessedFilters[] = $filterkey;
1657 @list($amount, $color) = explode(
'|', $parameter);
1658 $commandline .=
' -fill '.escapeshellarg(
'#'.preg_replace(
'#[^0-9A-F]#i',
'', $color));
1659 $commandline .=
' -colorize '.escapeshellarg(min(max(intval($amount), 0), 100));
1665 @list($amount, $color) = explode(
'|', $parameter);
1666 $amount = ($amount ? $amount : 80);
1668 $commandline .=
' -sepia-tone '.escapeshellarg(min(max(intval($amount), 0), 100).
'%');
1669 $successfullyProcessedFilters[] = $filterkey;
1675 @list($amount) = explode(
'|', $parameter);
1676 $amount = min(max(floatval($amount), 0.001), 10);
1677 if (number_format($amount, 3) !=
'1.000') {
1679 $commandline .=
' -gamma '.escapeshellarg($amount);
1680 $successfullyProcessedFilters[] = $filterkey;
1687 $commandline .=
' -negate';
1688 $successfullyProcessedFilters[] = $filterkey;
1693 @list($amount) = explode(
'|', $parameter);
1695 $commandline .=
' -threshold '.escapeshellarg(round(min(max(intval($amount), 0), 255) / 2.55).
'%');
1696 $commandline .=
' -dither';
1697 $commandline .=
' -monochrome';
1698 $successfullyProcessedFilters[] = $filterkey;
1704 @list($colors, $dither) = explode(
'|', $parameter);
1705 $colors = ($colors ? (int) $colors : 256);
1706 $dither = ((strlen($dither) > 0) ? (
bool) $dither :
true);
1707 $commandline .=
' -colors '.escapeshellarg(max($colors, 8));
1708 $commandline .= ($dither ?
' -dither' :
' +dither');
1709 $successfullyProcessedFilters[] = $filterkey;
1715 if (strpos(strtolower($parameter),
'x') !==
false) {
1716 $commandline .=
' -flop';
1718 if (strpos(strtolower($parameter),
'y') !==
false) {
1719 $commandline .=
' -flip';
1721 $successfullyProcessedFilters[] = $filterkey;
1727 $parameter = (!empty($parameter) ? $parameter : 2);
1728 $commandline .=
' -edge '.escapeshellarg(!empty($parameter) ? intval($parameter) : 1);
1729 $successfullyProcessedFilters[] = $filterkey;
1735 $parameter = (!empty($parameter) ? $parameter : 2);
1736 $commandline .=
' -emboss '.escapeshellarg(intval($parameter));
1737 if ($parameter < 2) {
1738 $commandline .=
' -negate';
1740 $successfullyProcessedFilters[] = $filterkey;
1745 @list($band,
$method, $threshold) = explode(
'|', $parameter);
1746 $band = ($band ? preg_replace(
'#[^RGBA\\*]#',
'', strtoupper($band)) :
'*');
1748 $threshold = ((strlen($threshold) > 0) ? min(max(floatval($threshold), 0), 100) : 0.1);
1750 $band = preg_replace(
'#[^RGBA\\*]#',
'', strtoupper($band));
1757 foreach ($this->fltr as $fltr_key => $fltr_value) {
1758 list($fltr_cmd) = explode(
'|', $fltr_value);
1759 if ($fltr_cmd ==
'wb') {
1760 $this->
DebugMessage(
'Setting "lvl" filter method to "0" (from "'.
$method.
'") because white-balance filter also enabled', __FILE__, __LINE__);
1773 $commandline .=
' -channel '.escapeshellarg(strtoupper($band));
1775 $threshold = preg_replace(
'#[^0-9\\.]#',
'', $threshold);
1777 $commandline .=
' -contrast-stretch \''.$threshold.
'%\'';
1779 $commandline .=
' +channel';
1781 $successfullyProcessedFilters[] = $filterkey;
1787 $commandline .=
' -channel '.escapeshellarg(strtoupper($band));
1789 $commandline .=
' -normalize';
1791 $commandline .=
' +channel';
1793 $successfullyProcessedFilters[] = $filterkey;
1797 $this->
DebugMessage(
'unsupported method ('.
$method.
') for "lvl" filter', __FILE__, __LINE__);
1800 if (isset($this->fltr[$filterkey]) && (
$method > 1)) {
1801 $this->fltr[$filterkey] = $command.
'|'.$band.
'|0|'.$threshold;
1802 $this->
DebugMessage(
'filter "lvl" remapped from method "'.
$method.
'" to method "0" because ImageMagick support is missing', __FILE__, __LINE__);
1808 @list($threshold) = explode(
'|', $parameter);
1809 $threshold = (!empty($threshold) ? min(max(floatval($threshold), 0), 100) : 0.1);
1810 $threshold = preg_replace(
'#[^0-9\\.]#',
'', $threshold);
1814 $commandline .=
' -channel R -contrast-stretch \''.$threshold.
'%\'';
1815 $commandline .=
' -channel G -contrast-stretch \''.$threshold.
'%\'';
1816 $commandline .=
' -channel B -contrast-stretch \''.$threshold.
'%\'';
1817 $commandline .=
' +channel';
1818 $successfullyProcessedFilters[] = $filterkey;
1824 @list($radius) = explode(
'|', $parameter);
1825 $radius = (!empty($radius) ? min(max(intval($radius), 0), 25) : 1);
1826 $commandline .=
' -blur '.escapeshellarg($radius);
1827 $successfullyProcessedFilters[] = $filterkey;
1832 @list($radius) = explode(
'|', $parameter);
1833 $radius = (!empty($radius) ? min(max(intval($radius), 0), 25) : 1);
1836 $commandline .=
' -gaussian-blur '.escapeshellarg($radius);
1837 $successfullyProcessedFilters[] = $filterkey;
1839 $commandline .=
' -gaussian '.escapeshellarg($radius);
1840 $successfullyProcessedFilters[] = $filterkey;
1846 @list($amount, $radius, $threshold) = explode(
'|', $parameter);
1847 $amount = ($amount ? min(max(intval($radius), 0), 255) : 80);
1848 $radius = ($radius ? min(max(intval($radius), 0), 10) : 0.5);
1849 $threshold = (strlen($threshold) ? min(max(intval($radius), 0), 50) : 3);
1850 $commandline .=
' -unsharp '.escapeshellarg(number_format(($radius * 2) - 1, 2,
'.',
'').
'x1+'.number_format($amount / 100, 2,
'.',
'').
'+'.number_format($threshold / 100, 2,
'.',
''));
1851 $successfullyProcessedFilters[] = $filterkey;
1858 @list($width, $rX, $rY, $color) = explode(
'|', $parameter);
1859 $width = intval($width);
1862 if ($width && !$rX && !$rY) {
1866 $commandline .=
' -border '.escapeshellarg(intval($width));
1867 $commandline .=
' -bordercolor '.escapeshellarg(
'#'.$color);
1869 if (preg_match(
'# \\-crop "([0-9]+)x([0-9]+)\\+0\\+0" #', $commandline, $matches)) {
1870 $commandline = str_replace(
' -crop "'.$matches[1].
'x'.$matches[2].
'+0+0" ',
' -crop '.escapeshellarg(($matches[1] - (2 * $width)).
'x'.($matches[2] - (2 * $width)).
'+0+0').
' ', $commandline);
1871 } elseif (preg_match(
'# \\-'.$IMresizeParameter.
' "([0-9]+)x([0-9]+)" #', $commandline, $matches)) {
1872 $commandline = str_replace(
' -'.$IMresizeParameter.
' "'.$matches[1].
'x'.$matches[2].
'" ',
' -'.$IMresizeParameter.
' '.escapeshellarg(($matches[1] - (2 * $width)).
'x'.($matches[2] - (2 * $width))).
' ', $commandline);
1874 $successfullyProcessedFilters[] = $filterkey;
1929 $this->
DebugMessage(
'Unknown $this->fltr['.$filterkey.
'] ('.$filtercommand.
') -- deleting filter command', __FILE__, __LINE__);
1930 $successfullyProcessedFilters[] = $filterkey;
1933 if (!isset($this->fltr[$filterkey])) {
1934 $this->
DebugMessage(
'Processed $this->fltr['.$filterkey.
'] ('.$filtercommand.
') with ImageMagick', __FILE__, __LINE__);
1936 $this->
DebugMessage(
'Skipping $this->fltr['.$filterkey.
'] ('.$filtercommand.
') with ImageMagick', __FILE__, __LINE__);
1940 if (count($this->fltr) > 0) {
1941 $this->useRawIMoutput =
false;
1944 if (preg_match(
'#jpe?g#i', $outputFormat) && $this->q) {
1946 $commandline .=
' -quality '.escapeshellarg($this->thumbnailQuality);
1947 if ($this->config_output_interlace) {
1949 $commandline .=
' -interlace line ';
1953 $commandline .=
' '.escapeshellarg(preg_replace(
'#[/\\\\]#',
DIRECTORY_SEPARATOR, $this->sourceFilename).(($outputFormat ==
'gif') ?
'' :
'['.intval($this->sfn).
']'));
1954 $commandline .=
' '.$outputFormat.
':'.escapeshellarg($IMtempfilename);
1955 if (!$this->iswindows) {
1956 $commandline .=
' 2>&1';
1958 $this->
DebugMessage(
'ImageMagick called as ('.$commandline.
')', __FILE__, __LINE__);
1961 if (!@file_exists($IMtempfilename) || !@filesize($IMtempfilename)) {
1962 $this->
FatalError(
'ImageMagick failed with message ('.trim($IMresult).
')');
1963 $this->
DebugMessage(
'ImageMagick failed with message ('.trim($IMresult).
')', __FILE__, __LINE__);
1964 if ($this->iswindows && !$IMresult) {
1965 $this->
DebugMessage(
'Check to make sure that PHP has read+write permissions to "'.dirname($IMtempfilename).
'"', __FILE__, __LINE__);
1970 foreach ($successfullyProcessedFilters as $dummy => $filterkey) {
1971 unset($this->fltr[$filterkey]);
1973 $this->IMresizedData = file_get_contents($IMtempfilename);
1974 $getimagesize_imresized = @GetImageSize($IMtempfilename);
1975 $this->
DebugMessage(
'GetImageSize('.$IMtempfilename.
') returned [w='.$getimagesize_imresized[0].
';h='.$getimagesize_imresized[1].
';f='.$getimagesize_imresized[2].
']', __FILE__, __LINE__);
1976 if (($this->config_max_source_pixels > 0) && (($getimagesize_imresized[0] * $getimagesize_imresized[1]) > $this->config_max_source_pixels)) {
1977 $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__);
1978 } elseif (function_exists(@$ImageCreateFunction) && ($this->gdimg_source = @$ImageCreateFunction($IMtempfilename))) {
1979 $this->source_width = ImageSX($this->gdimg_source);
1980 $this->source_height = ImageSY($this->gdimg_source);
1981 $this->
DebugMessage(
'ImageMagickThumbnailToGD::'.$ImageCreateFunction.
'() succeeded, $this->gdimg_source is now ('.$this->source_width.
'x'.$this->source_height.
')', __FILE__, __LINE__);
1982 $this->
DebugMessage(
'ImageMagickThumbnailToGD() returning $this->IMresizedData ('.strlen($this->IMresizedData).
' bytes)', __FILE__, __LINE__);
1984 $this->useRawIMoutput =
true;
1985 $this->
DebugMessage(
'$this->useRawIMoutput set to TRUE because '.@$ImageCreateFunction.
'('.$IMtempfilename.
') failed', __FILE__, __LINE__);
1990 if (file_exists($IMtempfilename)) {
1991 $this->
DebugMessage(
'deleting "'.$IMtempfilename.
'"', __FILE__, __LINE__);
1992 @unlink($IMtempfilename);
1995 } elseif ($this->issafemode) {
1996 $this->
DebugMessage(
'ImageMagickThumbnailToGD() aborting because PHP safe_mode is enabled and phpThumb_tempnam() failed', __FILE__, __LINE__);
1997 $this->useRawIMoutput =
false;
1999 if (file_exists($IMtempfilename)) {
2000 $this->
DebugMessage(
'deleting "'.$IMtempfilename.
'"', __FILE__, __LINE__);
2001 @unlink($IMtempfilename);
2003 $this->
DebugMessage(
'ImageMagickThumbnailToGD() aborting, phpThumb_tempnam() failed', __FILE__, __LINE__);
2006 $this->
DebugMessage(
'ImageMagickThumbnailToGD() aborting because ImageMagickCommandlineBase() failed', __FILE__, __LINE__);
2008 $this->useRawIMoutput =
false;
2014 if ($this->ra || $this->ar) {
2015 if (!function_exists(
'ImageRotate')) {
2016 $this->
DebugMessage(
'!function_exists(ImageRotate)', __FILE__, __LINE__);
2019 if (!include_once(dirname(__FILE__).
'/phpthumb.filters.php')) {
2020 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.filters.php" which is required for applying filters ('.implode(
';', $this->fltr).
')', __FILE__, __LINE__);
2026 return $this->
ErrorImage(
'Invalid hex color string "'.$this->config_background_hexcolor.
'" for parameter "bg"');
2032 $rotate_angle = floatval($this->ra);
2036 if ($this->ar ==
'x') {
2038 if ($this->sourceFilename) {
2039 if (function_exists(
'exif_read_data')) {
2040 if ($exif_data = @exif_read_data($this->sourceFilename,
'IFD0')) {
2042 switch (@$exif_data[
'Orientation']) {
2047 $rotate_angle = 180;
2050 $rotate_angle = 270;
2057 $this->
DebugMessage(
'EXIF auto-rotate failed because unknown $exif_data[Orientation] "'.@$exif_data[
'Orientation'].
'"', __FILE__, __LINE__);
2061 $this->
DebugMessage(
'EXIF auto-rotate set to '.$rotate_angle.
' degrees ($exif_data[Orientation] = "'.@$exif_data[
'Orientation'].
'")', __FILE__, __LINE__);
2063 $this->
DebugMessage(
'failed: exif_read_data('.$this->sourceFilename.
')', __FILE__, __LINE__);
2067 $this->
DebugMessage(
'!function_exists(exif_read_data)', __FILE__, __LINE__);
2071 $this->
DebugMessage(
'Cannot auto-rotate from EXIF data because $this->sourceFilename is empty', __FILE__, __LINE__);
2075 $this->
DebugMessage(
'Cannot auto-rotate from EXIF data because PHP is less than v4.2.0 ('.phpversion().
')', __FILE__, __LINE__);
2078 } elseif (($this->ar ==
'l') && ($this->source_height > $this->source_width)) {
2079 $rotate_angle = 270;
2080 } elseif (($this->ar ==
'L') && ($this->source_height > $this->source_width)) {
2082 } elseif (($this->ar ==
'p') && ($this->source_width > $this->source_height)) {
2084 } elseif (($this->ar ==
'P') && ($this->source_width > $this->source_height)) {
2085 $rotate_angle = 270;
2089 if ($rotate_angle % 90) {
2090 $this->is_alpha =
true;
2093 $this->source_width = ImageSX($this->gdimg_source);
2094 $this->source_height = ImageSY($this->gdimg_source);
2108 if (!$this->w || !$this->h) {
2112 $this->thumbnail_height =
$this->h;
2113 $this->is_alpha =
true;
2114 if ($this->thumbnail_image_width >= $this->thumbnail_width) {
2118 $this->thumbnail_image_height = round($this->thumbnail_image_width * $aspectratio);
2120 } elseif ($this->thumbnail_image_height < $this->thumbnail_height) {
2122 $this->thumbnail_image_width = round($this->thumbnail_image_height / $aspectratio);
2128 $this->thumbnail_image_width = round($this->thumbnail_image_height * $aspectratio);
2129 } elseif ($this->thumbnail_image_width < $this->thumbnail_width) {
2131 $this->thumbnail_image_height = round($this->thumbnail_image_width / $aspectratio);
2140 static $domain_is_allowed = array();
2141 $hostname = strtolower($hostname);
2142 if (!isset($domain_is_allowed[$hostname])) {
2143 $domain_is_allowed[$hostname] =
false;
2144 foreach ($allowed_domains as $valid_domain) {
2145 $starpos = strpos($valid_domain,
'*');
2146 if ($starpos !==
false) {
2147 $valid_domain = substr($valid_domain, $starpos + 1);
2148 if (preg_match(
'#'.preg_quote($valid_domain).
'$#', $hostname)) {
2149 $domain_is_allowed[$hostname] =
true;
2153 if (strtolower($valid_domain) === $hostname) {
2154 $domain_is_allowed[$hostname] =
true;
2160 return $domain_is_allowed[$hostname];
2167 if ($allow && $this->config_nooffsitelink_enabled && (@
$_SERVER[
'HTTP_REFERER'] || $this->config_nooffsitelink_require_refer)) {
2168 $this->
DebugMessage(
'AntiOffsiteLinking() checking $_SERVER[HTTP_REFERER] "'.@
$_SERVER[
'HTTP_REFERER'].
'"', __FILE__, __LINE__);
2169 foreach ($this->config_nooffsitelink_valid_domains as $key => $valid_domain) {
2171 list($clean_domain) = explode(
':', $valid_domain);
2172 $this->config_nooffsitelink_valid_domains[$key] = $clean_domain;
2179 $this->
ErrorImage(
'AntiOffsiteLinking() - "'.@$parsed_url[
'host'].
'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(
';', $this->config_nooffsitelink_valid_domains).
')');
2181 $this->
DebugMessage(
'AntiOffsiteLinking() - "'.@$parsed_url[
'host'].
'" is NOT in $this->config_nooffsitelink_valid_domains ('.implode(
';', $this->config_nooffsitelink_valid_domains).
')', __FILE__, __LINE__);
2183 $this->
DebugMessage(
'AntiOffsiteLinking() - "'.@$parsed_url[
'host'].
'" is in $this->config_nooffsitelink_valid_domains ('.implode(
';', $this->config_nooffsitelink_valid_domains).
')', __FILE__, __LINE__);
2187 if ($allow && $this->config_nohotlink_enabled && preg_match(
'#^(f|ht)tps?\://#i', $this->src)) {
2195 $this->
DebugMessage(
'AntiOffsiteLinking() - "'.$parsed_url[
'host'].
'" is NOT in $this->config_nohotlink_valid_domains ('.implode(
';', $this->config_nohotlink_valid_domains).
')', __FILE__, __LINE__);
2197 $this->
DebugMessage(
'AntiOffsiteLinking() - "'.$parsed_url[
'host'].
'" is in $this->config_nohotlink_valid_domains ('.implode(
';', $this->config_nohotlink_valid_domains).
')', __FILE__, __LINE__);
2202 $this->
DebugMessage(
'AntiOffsiteLinking() says this is allowed', __FILE__, __LINE__);
2207 return $this->
ErrorImage(
'Invalid hex color string "'.$this->config_error_bgcolor.
'" for $this->config_error_bgcolor');
2210 return $this->
ErrorImage(
'Invalid hex color string "'.$this->config_error_textcolor.
'" for $this->config_error_textcolor');
2214 return $this->
ErrorImage($message, $this->thumbnail_width, $this->thumbnail_height, $this->config_error_bgcolor, $this->config_error_textcolor, $this->config_error_fontsize);
2218 $this->config_nooffsitelink_watermark_src = $this->
ResolveFilenameToAbsolute($this->config_nooffsitelink_watermark_src);
2219 if (is_file($this->config_nooffsitelink_watermark_src)) {
2221 if (!include_once(dirname(__FILE__).
'/phpthumb.filters.php')) {
2222 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.filters.php" which is required for applying watermark', __FILE__, __LINE__);
2227 $phpthumbFilters->phpThumbObject = &$this;
2230 $phpthumbFilters->WatermarkOverlay($this->gdimg_output, $watermark_img,
'*', $opacity, $margin);
2231 ImageDestroy($watermark_img);
2232 unset($phpthumbFilters);
2236 $nohotlink_text_array = explode(
"\n", wordwrap($message, floor($this->thumbnail_width / ImageFontWidth($this->config_error_fontsize)),
"\n"));
2239 $topoffset = round(($this->thumbnail_height - (count($nohotlink_text_array) * ImageFontHeight($this->config_error_fontsize))) / 2);
2242 $this->
DebugMessage(
'AntiOffsiteLinking() writing '.count($nohotlink_text_array).
' lines of text "'.$message.
'" (in #'.$this->config_error_textcolor.
') on top of image', __FILE__, __LINE__);
2243 foreach ($nohotlink_text_array as $textline) {
2244 $leftoffset = max(0, round(($this->thumbnail_width - (strlen($textline) * ImageFontWidth($this->config_error_fontsize))) / 2));
2245 ImageString($this->gdimg_output, $this->config_error_fontsize, $leftoffset, $topoffset + ($rowcounter++ * ImageFontHeight($this->config_error_fontsize)), $textline, $nohotlink_text_color);
2256 if (!$this->is_alpha) {
2258 $this->
DebugMessage(
'skipping AlphaChannelFlatten() because !$this->is_alpha', __FILE__, __LINE__);
2261 switch ($this->thumbnailFormat) {
2265 $this->
DebugMessage(
'skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.
'")', __FILE__, __LINE__);
2271 $CurrentImageColorTransparent = ImageColorTransparent($this->gdimg_output);
2272 if ($CurrentImageColorTransparent == -1) {
2280 if ($img_alpha_mixdown_dither = @ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output))) {
2282 for (
$i = 0;
$i <= 255;
$i++) {
2283 $dither_color[
$i] = ImageColorAllocate($img_alpha_mixdown_dither,
$i,
$i,
$i);
2290 ImageSetPixel($img_alpha_mixdown_dither, $x, $y, $dither_color[($PixelColor[
'alpha'] * 2)]);
2295 ImageTrueColorToPalette($img_alpha_mixdown_dither,
true, 2);
2298 ImageTrueColorToPalette($this->gdimg_output,
true, 255);
2301 $TransparentColor = ImageColorAllocate($this->gdimg_output, 1, 254, 253);
2302 ImageColorTransparent($this->gdimg_output, $TransparentColor);
2305 $TransparentPixels = array();
2309 if ($AlphaChannelPixel[
'red'] > 127) {
2310 ImageSetPixel($this->gdimg_output, $x, $y, $TransparentColor);
2314 ImageDestroy($img_alpha_mixdown_dither);
2316 $this->
DebugMessage(
'AlphaChannelFlatten() set image to 255+1 colors with transparency for GIF output', __FILE__, __LINE__);
2320 $this->
DebugMessage(
'AlphaChannelFlatten() failed ImageCreate('.ImageSX($this->gdimg_output).
', '.ImageSY($this->gdimg_output).
')', __FILE__, __LINE__);
2326 $this->
DebugMessage(
'skipping AlphaChannelFlatten() because ($this->thumbnailFormat == "'.$this->thumbnailFormat.
'") and ImageColorTransparent returned "'.$CurrentImageColorTransparent.
'"', __FILE__, __LINE__);
2331 $this->
DebugMessage(
'continuing AlphaChannelFlatten() for output format "'.$this->thumbnailFormat.
'"', __FILE__, __LINE__);
2337 return $this->
ErrorImage(
'Invalid hex color string "'.$this->config_background_hexcolor.
'" for parameter "bg"');
2340 ImageFilledRectangle($gdimg_flatten_temp, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $background_color);
2341 ImageCopy($gdimg_flatten_temp, $this->gdimg_output, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height);
2343 ImageAlphaBlending($this->gdimg_output,
true);
2344 ImageSaveAlpha($this->gdimg_output,
false);
2345 ImageColorTransparent($this->gdimg_output, -1);
2346 ImageCopy($this->gdimg_output, $gdimg_flatten_temp, 0, 0, 0, 0, $this->thumbnail_width, $this->thumbnail_height);
2348 ImageDestroy($gdimg_flatten_temp);
2352 $this->
DebugMessage(
'ImageCreateFunction() failed', __FILE__, __LINE__);
2359 if ($this->fltr && is_array($this->fltr)) {
2360 if (!include_once(dirname(__FILE__).
'/phpthumb.filters.php')) {
2361 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.filters.php" which is required for applying filters ('.implode(
';', $this->fltr).
')', __FILE__, __LINE__);
2365 $phpthumbFilters->phpThumbObject = &$this;
2366 foreach ($this->fltr as $filtercommand) {
2367 @list($command, $parameter) = explode(
'|', $filtercommand, 2);
2368 $this->
DebugMessage(
'Attempting to process filter command "'.$command.
'('.$parameter.
')"', __FILE__, __LINE__);
2371 $phpthumbFilters->Brightness($this->gdimg_output, $parameter);
2375 $phpthumbFilters->Contrast($this->gdimg_output, $parameter);
2379 $phpthumbFilters->Desaturate($this->gdimg_output, $parameter,
'');
2383 $phpthumbFilters->Saturation($this->gdimg_output, $parameter,
'');
2387 $phpthumbFilters->Grayscale($this->gdimg_output);
2395 @list($amount, $color) = explode(
'|', $parameter, 2);
2396 $phpthumbFilters->Colorize($this->gdimg_output, $amount, $color);
2404 @list($amount, $color) = explode(
'|', $parameter, 2);
2405 $phpthumbFilters->Sepia($this->gdimg_output, $amount, $color);
2409 $phpthumbFilters->Gamma($this->gdimg_output, $parameter);
2413 $phpthumbFilters->Negative($this->gdimg_output);
2417 $phpthumbFilters->Threshold($this->gdimg_output, $parameter);
2425 @list($colors, $dither) = explode(
'|', $parameter, 2);
2426 $colors = ($colors ? (int) $colors : 256);
2427 $dither = ((strlen($dither) > 0) ? (
bool) $dither :
true);
2428 $phpthumbFilters->ReduceColorDepth($this->gdimg_output, $colors, $dither);
2432 $phpthumbFilters->Flip($this->gdimg_output, (strpos(strtolower($parameter),
'x') !==
false), (strpos(strtolower($parameter),
'y') !==
false));
2436 $phpthumbFilters->EdgeDetect($this->gdimg_output);
2440 $phpthumbFilters->Emboss($this->gdimg_output);
2444 @list($width, $color1, $color2) = explode(
'|', $parameter, 3);
2445 $phpthumbFilters->Bevel($this->gdimg_output, $width, $color1, $color2);
2449 @list($band,
$method, $threshold) = explode(
'|', $parameter, 3);
2450 $band = ($band ? preg_replace(
'#[^RGBA\\*]#',
'', strtoupper($band)) :
'*');
2452 $threshold = ((strlen($threshold) > 0) ? floatval($threshold) : 0.1);
2454 $phpthumbFilters->HistogramStretch($this->gdimg_output, $band,
$method, $threshold);
2458 $phpthumbFilters->WhiteBalance($this->gdimg_output, $parameter);
2466 @list($bands, $colors, $width, $height, $alignment, $opacity, $margin_x, $margin_y) = explode(
'|', $parameter, 8);
2467 $bands = ($bands ? $bands :
'*');
2468 $colors = ($colors ? $colors :
'');
2469 $width = ($width ? $width : 0.25);
2470 $height = ($height ? $height : 0.25);
2471 $alignment = ($alignment ? $alignment :
'BR');
2472 $opacity = ($opacity ? $opacity : 50);
2473 $margin_x = ($margin_x ? $margin_x : 5);
2474 $margin_y = $margin_y;
2475 $phpthumbFilters->HistogramOverlay($this->gdimg_output, $bands, $colors, $width, $height, $alignment, $opacity, $margin_x, $margin_y);
2479 @list($frame_width, $edge_width, $color_frame, $color1, $color2) = explode(
'|', $parameter, 5);
2480 $phpthumbFilters->Frame($this->gdimg_output, $frame_width, $edge_width, $color_frame, $color1, $color2);
2488 $this->is_alpha =
true;
2489 @list($distance, $width, $color, $angle, $fade) = explode(
'|', $parameter, 5);
2490 $phpthumbFilters->DropShadow($this->gdimg_output, $distance, $width, $color, $angle, $fade);
2499 if (@is_readable($mask_filename) && ($fp_mask = @fopen($mask_filename,
'rb'))) {
2500 $MaskImageData =
'';
2502 $buffer = fread($fp_mask, 8192);
2503 $MaskImageData .= $buffer;
2504 }
while (strlen($buffer) > 0);
2507 $this->is_alpha =
true;
2508 $phpthumbFilters->ApplyMask($gdimg_mask, $this->gdimg_output);
2509 ImageDestroy($gdimg_mask);
2511 $this->
DebugMessage(
'ImageCreateFromStringReplacement() failed for "'.$mask_filename.
'"', __FILE__, __LINE__);
2514 $this->
DebugMessage(
'Cannot open mask file "'.$mask_filename.
'"', __FILE__, __LINE__);
2523 $this->is_alpha =
true;
2524 $phpthumbFilters->Elipse($this->gdimg_output);
2532 @list($radius_x, $radius_y) = explode(
'|', $parameter, 2);
2533 if (($radius_x < 1) || ($radius_y < 1)) {
2534 $this->
DebugMessage(
'Skipping RoundedImageCorners('.$radius_x.
', '.$radius_y.
') because x/y radius is less than 1', __FILE__, __LINE__);
2537 $this->is_alpha =
true;
2538 $phpthumbFilters->RoundedImageCorners($this->gdimg_output, $radius_x, $radius_y);
2542 @list($left, $right, $top, $bottom) = explode(
'|', $parameter, 4);
2543 $phpthumbFilters->Crop($this->gdimg_output, $left, $right, $top, $bottom);
2547 @list($border_width, $radius_x, $radius_y, $hexcolor_border) = explode(
'|', $parameter, 4);
2548 $this->is_alpha =
true;
2549 $phpthumbFilters->ImageBorder($this->gdimg_output, $border_width, $radius_x, $radius_y, $hexcolor_border);
2553 @list($filename, $underlay, $margin, $opacity) = explode(
'|', $parameter, 4);
2554 $underlay = (bool) ($underlay ? $underlay :
false);
2555 $margin = ((strlen($margin) > 0) ? $margin : ($underlay ? 0.1 : 0.0));
2556 $opacity = ((strlen($opacity) > 0) ? $opacity : 100);
2557 if (($margin > 0) && ($margin < 1)) {
2558 $margin = min(0.499, $margin);
2559 } elseif (($margin > -1) && ($margin < 0)) {
2560 $margin = max(-0.499, $margin);
2564 if (@is_readable($filename) && ($fp_watermark = @fopen($filename,
'rb'))) {
2565 $WatermarkImageData =
'';
2567 $buffer = fread($fp_watermark, 8192);
2568 $WatermarkImageData .= $buffer;
2569 }
while (strlen($buffer) > 0);
2570 fclose($fp_watermark);
2573 $resized_x = max(1, ImageSX($this->gdimg_output) - round(2 * (ImageSX($this->gdimg_output) * $margin)));
2574 $resized_y = max(1, ImageSY($this->gdimg_output) - round(2 * (ImageSY($this->gdimg_output) * $margin)));
2576 $resized_x = max(1, ImageSX($this->gdimg_output) - round(2 * $margin));
2577 $resized_y = max(1, ImageSY($this->gdimg_output) - round(2 * $margin));
2583 ImageAlphaBlending($img_watermark_resized,
false);
2584 ImageSaveAlpha($img_watermark_resized,
true);
2585 $this->
ImageResizeFunction($img_watermark_resized, $img_watermark, 0, 0, 0, 0, ImageSX($img_watermark_resized), ImageSY($img_watermark_resized), ImageSX($img_watermark), ImageSY($img_watermark));
2587 ImageAlphaBlending($img_source_resized,
false);
2588 ImageSaveAlpha($img_source_resized,
true);
2589 $this->
ImageResizeFunction($img_source_resized, $this->gdimg_output, 0, 0, 0, 0, ImageSX($img_source_resized), ImageSY($img_source_resized), ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2590 $phpthumbFilters->WatermarkOverlay($img_watermark_resized, $img_source_resized,
'C', $opacity, $margin);
2591 ImageCopy($this->gdimg_output, $img_watermark_resized, 0, 0, 0, 0, ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2593 $this->
DebugMessage(
'phpthumb_functions::ImageCreateFunction('.$resized_x.
', '.$resized_y.
')', __FILE__, __LINE__);
2595 ImageDestroy($img_watermark_resized);
2597 $this->
DebugMessage(
'phpthumb_functions::ImageCreateFunction('.ImageSX($this->gdimg_output).
', '.ImageSY($this->gdimg_output).
')', __FILE__, __LINE__);
2603 ImageAlphaBlending($img_watermark_resized,
false);
2604 ImageSaveAlpha($img_watermark_resized,
true);
2605 $this->
ImageResizeFunction($img_watermark_resized, $img_watermark, 0, 0, 0, 0, ImageSX($img_watermark_resized), ImageSY($img_watermark_resized), ImageSX($img_watermark), ImageSY($img_watermark));
2606 $phpthumbFilters->WatermarkOverlay($this->gdimg_output, $img_watermark_resized,
'C', $opacity, $margin);
2607 ImageDestroy($img_watermark_resized);
2609 $this->
DebugMessage(
'phpthumb_functions::ImageCreateFunction('.$resized_x.
', '.$resized_y.
')', __FILE__, __LINE__);
2613 ImageDestroy($img_watermark);
2616 $this->
DebugMessage(
'ImageCreateFromStringReplacement() failed for "'.$filename.
'"', __FILE__, __LINE__);
2619 $this->
DebugMessage(
'Cannot open overlay file "'.$filename.
'"', __FILE__, __LINE__);
2624 @list($filename, $alignment, $opacity, $margin[
'x'], $margin[
'y'], $rotate_angle) = explode(
'|', $parameter, 6);
2626 $alignment = ($alignment ? $alignment :
'BR');
2627 $opacity = (strlen($opacity) ? intval($opacity) : 50);
2628 $rotate_angle = (strlen($rotate_angle) ? intval($rotate_angle) : 0);
2629 if (!preg_match(
'#^([0-9\\.\\-]*)x([0-9\\.\\-]*)$#i', $alignment, $matches)) {
2630 $margins = array(
'x',
'y');
2631 foreach ($margins as $xy) {
2632 $margin[$xy] = (strlen($margin[$xy]) ? $margin[$xy] : 5);
2633 if (($margin[$xy] > 0) && ($margin[$xy] < 1)) {
2634 $margin[$xy] = min(0.499, $margin[$xy]);
2635 } elseif (($margin[$xy] > -1) && ($margin[$xy] < 0)) {
2636 $margin[$xy] = max(-0.499, $margin[$xy]);
2642 if (@is_readable($filename)) {
2644 if ($rotate_angle !== 0) {
2645 $phpthumbFilters->ImprovedImageRotate($img_watermark, $rotate_angle);
2647 if (preg_match(
'#^([0-9\\.\\-]*)x([0-9\\.\\-]*)$#i', $alignment, $matches)) {
2648 $watermark_max_width = intval($margin[
'x'] ? $margin[
'x'] : ImageSX($img_watermark));
2649 $watermark_max_height = intval($margin[
'y'] ? $margin[
'y'] : ImageSY($img_watermark));
2651 $this->
DebugMessage(
'Scaling watermark by a factor of '.number_format($scale, 4), __FILE__, __LINE__);
2652 if (($scale > 1) || ($scale < 1)) {
2654 ImageAlphaBlending($img_watermark2,
false);
2655 ImageSaveAlpha($img_watermark2,
true);
2656 $this->
ImageResizeFunction($img_watermark2, $img_watermark, 0, 0, 0, 0, ImageSX($img_watermark2), ImageSY($img_watermark2), ImageSX($img_watermark), ImageSY($img_watermark));
2657 $img_watermark = $img_watermark2;
2659 $this->
DebugMessage(
'ImageCreateFunction('.($scale * ImageSX($img_watermark)).
', '.($scale * ImageSX($img_watermark)).
') failed', __FILE__, __LINE__);
2662 $watermark_dest_x = round($matches[1] - (ImageSX($img_watermark) / 2));
2663 $watermark_dest_y = round($matches[2] - (ImageSY($img_watermark) / 2));
2664 $alignment = $watermark_dest_x.
'x'.$watermark_dest_y;
2666 $phpthumbFilters->WatermarkOverlay($this->gdimg_output, $img_watermark, $alignment, $opacity, $margin[
'x'], $margin[
'y']);
2667 ImageDestroy($img_watermark);
2668 if (isset($img_watermark2) && is_resource($img_watermark2)) {
2669 ImageDestroy($img_watermark2);
2672 $this->
DebugMessage(
'ImageCreateFromFilename() failed for "'.$filename.
'"', __FILE__, __LINE__);
2675 $this->
DebugMessage(
'!is_readable('.$filename.
')', __FILE__, __LINE__);
2680 @list($text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend) = explode(
'|', $parameter, 11);
2681 $text = ($text ? $text :
'');
2682 $size = ($size ? $size : 3);
2683 $alignment = ($alignment ? $alignment :
'BR');
2684 $hex_color = ($hex_color ? $hex_color :
'000000');
2685 $ttffont = ($ttffont ? $ttffont :
'');
2686 $opacity = (strlen($opacity) ? $opacity : 50);
2687 $margin = (strlen($margin) ? $margin : 5);
2688 $angle = (strlen($angle) ? $angle : 0);
2689 $bg_color = ($bg_color ? $bg_color :
false);
2690 $bg_opacity = ($bg_opacity ? $bg_opacity : 0);
2691 $fillextend = ($fillextend ? $fillextend :
'');
2693 if (basename($ttffont) == $ttffont) {
2694 $ttffont = realpath($this->config_ttf_directory.DIRECTORY_SEPARATOR.$ttffont);
2698 $phpthumbFilters->WatermarkText($this->gdimg_output, $text, $size, $alignment, $hex_color, $ttffont, $opacity, $margin, $angle, $bg_color, $bg_opacity, $fillextend);
2702 @list($radius) = explode(
'|', $parameter, 1);
2703 $radius = ($radius ? $radius : 1);
2705 $phpthumbFilters->Blur($this->gdimg_output, $radius);
2712 $phpthumbFilters->BlurGaussian($this->gdimg_output);
2716 $phpthumbFilters->BlurSelective($this->gdimg_output);
2720 $phpthumbFilters->MeanRemoval($this->gdimg_output);
2724 $phpthumbFilters->Smooth($this->gdimg_output, $parameter);
2728 @list($amount, $radius, $threshold) = explode(
'|', $parameter, 3);
2729 $amount = ($amount ? $amount : 80);
2730 $radius = ($radius ? $radius : 0.5);
2731 $threshold = (strlen($threshold) ? $threshold : 3);
2734 if (!@include_once(dirname(__FILE__).
'/phpthumb.unsharp.php')) {
2735 $include_error = ob_get_contents();
2736 if ($include_error) {
2737 $this->
DebugMessage(
'include_once("'.dirname(__FILE__).
'/phpthumb.unsharp.php") generated message: "'.$include_error.
'"', __FILE__, __LINE__);
2739 $this->
DebugMessage(
'Error including "'.dirname(__FILE__).
'/phpthumb.unsharp.php" which is required for unsharp masking', __FILE__, __LINE__);
2752 @list($newwidth, $newheight, $stretch) = explode(
'|', $parameter);
2753 $newwidth = (!$newwidth ? ImageSX($this->gdimg_output) : ((($newwidth > 0) && ($newwidth < 1)) ? round($newwidth * ImageSX($this->gdimg_output)) : round($newwidth)));
2754 $newheight = (!$newheight ? ImageSY($this->gdimg_output) : ((($newheight > 0) && ($newheight < 1)) ? round($newheight * ImageSY($this->gdimg_output)) : round($newheight)));
2755 $stretch = ($stretch ?
true :
false);
2761 $scale_y = $scale_x;
2763 $this->
DebugMessage(
'Scaling watermark ('.($stretch ?
'with' :
'without').
' stretch) by a factor of "'.number_format($scale_x, 4).
' x '.number_format($scale_y, 4).
'"', __FILE__, __LINE__);
2764 if (($scale_x > 1) || ($scale_x < 1) || ($scale_y > 1) || ($scale_y < 1)) {
2766 ImageCopy($img_temp, $this->gdimg_output, 0, 0, 0, 0, ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2769 ImageAlphaBlending($this->gdimg_output,
false);
2770 ImageSaveAlpha($this->gdimg_output,
true);
2771 $this->
ImageResizeFunction($this->gdimg_output, $img_temp, 0, 0, 0, 0, ImageSX($this->gdimg_output), ImageSY($this->gdimg_output), ImageSX($img_temp), ImageSY($img_temp));
2773 $this->
DebugMessage(
'ImageCreateFunction('.($scale_x * ImageSX($img_temp)).
', '.($scale_y * ImageSY($img_temp)).
') failed', __FILE__, __LINE__);
2775 ImageDestroy($img_temp);
2777 $this->
DebugMessage(
'ImageCreateFunction('.ImageSX($this->gdimg_output).
', '.ImageSY($this->gdimg_output).
') failed', __FILE__, __LINE__);
2783 @list($angle, $bgcolor) = explode(
'|', $parameter, 2);
2784 $phpthumbFilters->ImprovedImageRotate($this->gdimg_output, $angle, $bgcolor);
2788 @list($hexcolor, $min_limit, $max_limit) = explode(
'|', $parameter, 3);
2790 $this->
DebugMessage(
'Skipping SourceTransparentColor hex color is invalid ('.$hexcolor.
')', __FILE__, __LINE__);
2793 $min_limit = (strlen($min_limit) ? $min_limit : 5);
2794 $max_limit = (strlen($max_limit) ? $max_limit : 10);
2795 if ($gdimg_mask = $phpthumbFilters->SourceTransparentColorMask($this->gdimg_output, $hexcolor, $min_limit, $max_limit)) {
2796 $this->is_alpha =
true;
2797 $phpthumbFilters->ApplyMask($gdimg_mask, $this->gdimg_output);
2798 ImageDestroy($gdimg_mask);
2800 $this->
DebugMessage(
'SourceTransparentColorMask() failed for "'.$mask_filename.
'"', __FILE__, __LINE__);
2804 $this->
DebugMessage(
'Finished processing filter command "'.$command.
'('.$parameter.
')"', __FILE__, __LINE__);
2816 if ($this->maxb > 0) {
2817 switch ($this->thumbnailFormat) {
2820 $imgRenderFunction =
'image'.$this->thumbnailFormat;
2823 $imgRenderFunction($this->gdimg_output);
2824 $imgdata = ob_get_contents();
2827 if (strlen($imgdata) > $this->maxb) {
2828 for (
$i = 8;
$i >= 1;
$i--) {
2829 $tempIMG = ImageCreateTrueColor(ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2830 ImageCopy($tempIMG, $this->gdimg_output, 0, 0, 0, 0, ImageSX($this->gdimg_output), ImageSY($this->gdimg_output));
2831 ImageTrueColorToPalette($tempIMG,
true, pow(2,
$i));
2833 $imgRenderFunction($tempIMG);
2834 $imgdata = ob_get_contents();
2837 if (strlen($imgdata) <= $this->maxb) {
2838 ImageTrueColorToPalette($this->gdimg_output,
true, pow(2,
$i));
2843 if (strlen($imgdata) > $this->maxb) {
2844 ImageTrueColorToPalette($this->gdimg_output,
true, pow(2,
$i));
2851 ImageJPEG($this->gdimg_output);
2852 $imgdata = ob_get_contents();
2856 if (strlen($imgdata) > $this->maxb) {
2857 for (
$i = 3;
$i < 20;
$i++) {
2858 $q = round(100 * (1 - log10(
$i / 2)));
2860 ImageJPEG($this->gdimg_output,
'',
$q);
2861 $imgdata = ob_get_contents();
2864 $this->thumbnailQuality =
$q;
2865 if (strlen($imgdata) <= $this->maxb) {
2870 if (strlen($imgdata) > $this->maxb) {
2885 $this->
DebugMessage(
'CalculateThumbnailDimensions() starting with [W,H,sx,sy,sw,sh] initially set to ['.$this->source_width.
','.$this->source_height.
','.$this->sx.
','.$this->sy.
','.$this->sw.
','.$this->sh.
']', __FILE__, __LINE__);
2887 $this->thumbnailCropX = ($this->sx ? (($this->sx >= 2) ? $this->sx : round($this->sx * $this->source_width)) : 0);
2889 $this->thumbnailCropY = ($this->sy ? (($this->sy >= 2) ? $this->sy : round($this->sy * $this->source_height)) : 0);
2891 $this->thumbnailCropW = ($this->sw ? (($this->sw >= 2) ? $this->sw : round($this->sw * $this->source_width)) : $this->source_width);
2893 $this->thumbnailCropH = ($this->sh ? (($this->sh >= 2) ? $this->sh : round($this->sh * $this->source_height)) : $this->source_height);
2897 $this->thumbnailCropW = max(1, min($this->thumbnailCropW, $this->source_width - $this->thumbnailCropX));
2898 $this->thumbnailCropH = max(1, min($this->thumbnailCropH, $this->source_height - $this->thumbnailCropY));
2900 $this->
DebugMessage(
'CalculateThumbnailDimensions() starting with [x,y,w,h] initially set to ['.$this->thumbnailCropX.
','.$this->thumbnailCropY.
','.$this->thumbnailCropW.
','.$this->thumbnailCropH.
']', __FILE__, __LINE__);
2903 if ($this->zc && $this->w && $this->h) {
2908 $scaling_X = $this->source_width /
$this->w;
2909 $scaling_Y = $this->source_height /
$this->h;
2910 if ($scaling_X > $scaling_Y) {
2912 $allowable_width = $this->source_width / $scaling_X * $scaling_Y;
2913 $this->thumbnailCropW = round($allowable_width);
2914 $this->thumbnailCropX = round(($this->source_width - $allowable_width) / 2);
2916 } elseif ($scaling_Y > $scaling_X) {
2918 $allowable_height = $this->source_height / $scaling_Y * $scaling_X;
2919 $this->thumbnailCropH = round($allowable_height);
2920 $this->thumbnailCropY = round(($this->source_height - $allowable_height) / 2);
2926 $this->thumbnail_height =
$this->h;
2930 } elseif ($this->iar && $this->w && $this->h) {
2935 $this->thumbnail_height =
$this->h;
2943 if ($this->w && $this->h) {
2944 $maxwidth = min($this->w, $this->h * $original_aspect_ratio);
2945 $maxheight = min($this->h, $this->w / $original_aspect_ratio);
2946 } elseif ($this->w) {
2948 $maxheight = $this->w / $original_aspect_ratio;
2949 } elseif ($this->h) {
2950 $maxwidth = $this->h * $original_aspect_ratio;
2960 $maxwidth = min($maxwidth, $maxheight * $original_aspect_ratio);
2961 $maxheight = min($maxheight, $maxwidth / $original_aspect_ratio);
2965 $this->thumbnail_image_width = $maxwidth;
2966 $this->thumbnail_image_height = $maxheight;
2967 $this->thumbnail_width = $maxwidth;
2968 $this->thumbnail_height = $maxheight;
2973 $this->thumbnail_width = max(1, floor($this->thumbnail_width));
2974 $this->thumbnail_height = max(1, floor($this->thumbnail_height));
2987 ImageSaveAlpha($this->gdimg_output,
true);
2990 ImageAlphaBlending($this->gdimg_output,
false);
2992 ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $output_full_alpha);
2996 $current_transparent_color = ImageColorTransparent($this->gdimg_source);
2997 if ($this->bg || (@$current_transparent_color >= 0)) {
3001 return $this->
ErrorImage(
'Invalid hex color string "'.$this->config_background_hexcolor.
'" for parameter "bg"');
3004 ImageFilledRectangle($this->gdimg_output, 0, 0, $this->thumbnail_width, $this->thumbnail_height, $background_color);
3009 $this->
DebugMessage(
'CreateGDoutput() returning canvas "'.$this->thumbnail_width.
'x'.$this->thumbnail_height.
'"', __FILE__, __LINE__);
3014 $this->
DebugMessage(
'SetOrientationDependantWidthHeight() starting with "'.$this->source_width.
'"x"'.$this->source_height.
'"', __FILE__, __LINE__);
3015 if ($this->source_height > $this->source_width) {
3019 } elseif ($this->source_height < $this->source_width) {
3030 $this->
DebugMessage(
'SetOrientationDependantWidthHeight() setting w="'.intval($this->w).
'", h="'.intval($this->h).
'"', __FILE__, __LINE__);
3035 $this->
DebugMessage(
'starting ExtractEXIFgetImageSize()', __FILE__, __LINE__);
3037 if (preg_match(
'#^http:#i', $this->src) && !$this->sourceFilename && $this->rawImageData) {
3040 if (is_null($this->getimagesizeinfo)) {
3041 if ($this->sourceFilename) {
3042 $this->getimagesizeinfo = @GetImageSize($this->sourceFilename);
3043 $this->source_width = $this->getimagesizeinfo[0];
3044 $this->source_height = $this->getimagesizeinfo[1];
3045 $this->
DebugMessage(
'GetImageSize('.$this->sourceFilename.
') says image is '.$this->source_width.
'x'.$this->source_height, __FILE__, __LINE__);
3047 $this->
DebugMessage(
'skipping GetImageSize() because $this->sourceFilename is empty', __FILE__, __LINE__);
3050 $this->
DebugMessage(
'skipping GetImageSize() because !is_null($this->getimagesizeinfo)', __FILE__, __LINE__);
3053 if (is_resource($this->gdimg_source)) {
3055 $this->source_width = ImageSX($this->gdimg_source);
3056 $this->source_height = ImageSY($this->gdimg_source);
3060 } elseif ($this->rawImageData && !$this->sourceFilename) {
3063 $this->
DebugMessage(
'NOT bypassing EXIF and GetImageSize sections because source image is too large for GD ('.$this->source_width.
'x'.$this->source_width.
'='.($this->source_width * $this->source_height * 5).
'MB)', __FILE__, __LINE__);
3065 $this->
DebugMessage(
'bypassing EXIF and GetImageSize sections because $this->rawImageData is set, and $this->sourceFilename is not set, and source image is not too large for GD ('.$this->source_width.
'x'.$this->source_width.
'='.($this->source_width * $this->source_height * 5).
'MB)', __FILE__, __LINE__);
3070 if (is_null($this->getimagesizeinfo)) {
3071 $this->getimagesizeinfo = @GetImageSize($this->sourceFilename);
3074 if (!empty($this->getimagesizeinfo)) {
3076 $this->getimagesizeinfo[
'filesize'] = @filesize($this->sourceFilename);
3077 } elseif (!$this->rawImageData) {
3078 $this->
DebugMessage(
'GetImageSize("'.$this->sourceFilename.
'") failed', __FILE__, __LINE__);
3081 if ($this->config_prefer_imagemagick) {
3085 $this->
DebugMessage(
'ImageMagickThumbnailToGD() failed', __FILE__, __LINE__);
3088 $this->source_width = $this->getimagesizeinfo[0];
3089 $this->source_height = $this->getimagesizeinfo[1];
3094 switch ($this->getimagesizeinfo[2]) {
3095 case IMAGETYPE_JPEG:
3096 case IMAGETYPE_TIFF_II:
3097 case IMAGETYPE_TIFF_MM:
3098 $this->exif_raw_data = @exif_read_data($this->sourceFilename, 0,
true);
3102 if (function_exists(
'exif_thumbnail') && ($this->getimagesizeinfo[2] == IMAGETYPE_JPEG)) {
3105 $this->exif_thumbnail_width =
'';
3106 $this->exif_thumbnail_height =
'';
3107 $this->exif_thumbnail_type =
'';
3112 $this->exif_thumbnail_data = @exif_thumbnail($this->sourceFilename, $this->exif_thumbnail_width, $this->exif_thumbnail_height, $this->exif_thumbnail_type);
3118 $this->exif_thumbnail_data = exif_thumbnail($this->sourceFilename);
3119 $exit_thumbnail_error = ob_get_contents();
3121 if (!$exit_thumbnail_error && $this->exif_thumbnail_data) {
3124 $this->exif_thumbnail_width = ImageSX($gdimg_exif_temp);
3125 $this->exif_thumbnail_height = ImageSY($gdimg_exif_temp);
3126 $this->exif_thumbnail_type = 2;
3127 unset($gdimg_exif_temp);
3129 return $this->
ErrorImage(
'Failed - $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data) in '.__FILE__.
' on line '.__LINE__);
3136 } elseif (!function_exists(
'exif_thumbnail')) {
3138 $this->
DebugMessage(
'exif_thumbnail() does not exist, cannot extract EXIF thumbnail', __FILE__, __LINE__);
3142 $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__);
3145 if ($this->config_use_exif_thumbnail_for_speed && $this->exif_thumbnail_data) {
3150 if (number_format($source_ar, 2) != number_format($exif_ar, 2)) {
3151 $this->
DebugMessage(
'not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.
' != '.$exif_ar.
')', __FILE__, __LINE__);
3154 if ($this->w && ($this->w != $this->exif_thumbnail_width)) {
3155 $this->
DebugMessage(
'not using EXIF thumbnail because $this->w != $this->exif_thumbnail_width ('.$this->w.
' != '.$this->exif_thumbnail_width.
')', __FILE__, __LINE__);
3158 if ($this->h && ($this->h != $this->exif_thumbnail_height)) {
3159 $this->
DebugMessage(
'not using EXIF thumbnail because $this->h != $this->exif_thumbnail_height ('.$this->h.
' != '.$this->exif_thumbnail_height.
')', __FILE__, __LINE__);
3162 $CannotBeSetParameters = array(
'sx',
'sy',
'sh',
'sw',
'far',
'bg',
'bc',
'fltr',
'phpThumbDebug');
3163 foreach ($CannotBeSetParameters as $parameter) {
3164 if ($this->$parameter) {
3170 $this->
DebugMessage(
'setting $this->gdimg_source = $this->ImageCreateFromStringReplacement($this->exif_thumbnail_data)', __FILE__, __LINE__);
3172 $this->source_width = ImageSX($this->gdimg_source);
3173 $this->source_height = ImageSY($this->gdimg_source);
3178 if (($this->config_max_source_pixels > 0) && (($this->source_width * $this->source_height) > $this->config_max_source_pixels)) {
3184 $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__);
3196 if (!is_null($this->cache_filename)) {
3197 $this->
DebugMessage(
'$this->cache_filename already set, skipping SetCacheFilename()', __FILE__, __LINE__);
3202 if (!$this->config_cache_directory) {
3203 $this->
DebugMessage(
'SetCacheFilename() failed because $this->config_cache_directory is empty', __FILE__, __LINE__);
3207 if (!$this->sourceFilename && !$this->rawImageData && $this->src) {
3211 if ($this->config_cache_default_only_suffix && $this->sourceFilename) {
3216 if (strpos($this->config_cache_default_only_suffix,
'*') ===
false) {
3217 $this->
DebugMessage(
'aborting simplified caching filename because no * in "'.$this->config_cache_default_only_suffix.
'"', __FILE__, __LINE__);
3219 preg_match(
'#(.+)(\\.[a-z0-9]+)?$#i', basename($this->sourceFilename), $matches);
3220 $this->cache_filename = $this->config_cache_directory.DIRECTORY_SEPARATOR.rawurlencode(str_replace(
'*', @$matches[1], $this->config_cache_default_only_suffix)).
'.'.strtolower($this->thumbnailFormat);
3225 $this->cache_filename =
'';
3226 $broad_directory_name =
'';
3228 $broad_directory_name = strtolower(md5($this->
new));
3229 $this->cache_filename .=
'_new'.$broad_directory_name;
3230 } elseif ($this->md5s) {
3232 $this->
DebugMessage(
'SetCacheFilename() _raw set from $this->md5s = "'.$this->md5s.
'"', __FILE__, __LINE__);
3234 $this->cache_filename .=
'_raw'.$this->md5s;
3235 } elseif (!$this->src && $this->rawImageData) {
3236 $this->
DebugMessage(
'SetCacheFilename() _raw set from md5($this->rawImageData) = "'.md5($this->rawImageData).
'"', __FILE__, __LINE__);
3237 $broad_directory_name = strtolower(md5($this->rawImageData));
3238 $this->cache_filename .=
'_raw'.$broad_directory_name;
3240 $this->
DebugMessage(
'SetCacheFilename() _src set from md5($this->sourceFilename) "'.$this->sourceFilename.
'" = "'.md5($this->sourceFilename).
'"', __FILE__, __LINE__);
3241 $broad_directory_name = strtolower(md5($this->sourceFilename));
3242 $this->cache_filename .=
'_src'.$broad_directory_name;
3244 if (@
$_SERVER[
'HTTP_REFERER'] && $this->config_nooffsitelink_enabled) {
3247 if (@$parsed_url1[
'host'] && @$parsed_url2[
'host'] && ($parsed_url1[
'host'] != $parsed_url2[
'host'])) {
3249 $this->cache_filename .=
'_offsite';
3253 $ParametersString =
'';
3254 if ($this->fltr && is_array($this->fltr)) {
3255 $ParametersString .=
'_fltr'.implode(
'_fltr', $this->fltr);
3257 $FilenameParameters1 = array(
'ar',
'bg',
'bc',
'far',
'sx',
'sy',
'sw',
'sh',
'zc');
3258 foreach ($FilenameParameters1 as $key) {
3260 $ParametersString .=
'_'.$key.$this->$key;
3263 $FilenameParameters2 = array(
'h',
'w',
'wl',
'wp',
'ws',
'hp',
'hs',
'xto',
'ra',
'iar',
'aoe',
'maxb',
'sfn',
'dpi');
3264 foreach ($FilenameParameters2 as $key) {
3266 $ParametersString .=
'_'.$key.intval($this->$key);
3269 if ($this->thumbnailFormat ==
'jpeg') {
3271 $ParametersString .=
'_q'.intval($this->thumbnailQuality);
3273 $this->
DebugMessage(
'SetCacheFilename() _par set from md5('.$ParametersString.
')', __FILE__, __LINE__);
3274 $this->cache_filename .=
'_par'.strtolower(md5($ParametersString));
3280 } elseif (!$this->config_cache_source_filemtime_ignore_remote && preg_match(
'#^(f|ht)tps?\://#i', $this->src)) {
3282 } elseif (!$this->config_cache_source_filemtime_ignore_local && $this->src && !$this->rawImageData) {
3283 $this->cache_filename .=
'_dat'.intval(@filemtime($this->sourceFilename));
3286 $this->cache_filename .=
'.'.strtolower($this->thumbnailFormat);
3287 $broad_directories =
'';
3292 $this->cache_filename = $this->config_cache_directory.$broad_directories.DIRECTORY_SEPARATOR.$this->config_cache_prefix.rawurlencode($this->cache_filename);
3298 if (!$this->config_max_source_pixels) {
3301 if (function_exists(
'memory_get_usage')) {
3302 $available_memory = max(intval(ini_get(
'memory_limit')), intval(get_cfg_var(
'memory_limit'))) * 1048576;
3303 $available_memory -= memory_get_usage();
3304 return (
bool) (($width * $height * 5) > $available_memory);
3306 return (
bool) (($width * $height) > $this->config_max_source_pixels);
3312 $ImageCreateWasAttempted =
false;
3315 $this->
DebugMessage(
'starting ImageCreateFromFilename('.$filename.
')', __FILE__, __LINE__);
3318 $ImageCreateFromFunction = array(
3319 1 =>
'ImageCreateFromGIF',
3320 2 =>
'ImageCreateFromJPEG',
3321 3 =>
'ImageCreateFromPNG',
3322 15 =>
'ImageCreateFromWBMP',
3331 if (function_exists($ImageCreateFromFunctionName)) {
3332 $this->
DebugMessage(
'Calling '.$ImageCreateFromFunctionName.
'('.$filename.
')', __FILE__, __LINE__);
3333 $ImageCreateWasAttempted =
true;
3334 $gd_image = $ImageCreateFromFunctionName($filename);
3336 $this->
DebugMessage(
'NOT calling '.$ImageCreateFromFunctionName.
'('.$filename.
') because !function_exists('.$ImageCreateFromFunctionName.
')', __FILE__, __LINE__);
3352 $this->
DebugMessage(
'No built-in image creation function for image type "'.@$getimagesizeinfo[2].
'" ($getimagesizeinfo[2])', __FILE__, __LINE__);
3356 $this->
DebugMessage(
'Unknown value for $getimagesizeinfo[2]: "'.@$getimagesizeinfo[2].
'"', __FILE__, __LINE__);
3364 $this->
DebugMessage(
'empty $filename or GetImageSize('.$filename.
') failed', __FILE__, __LINE__);
3369 if ($ImageCreateWasAttempted) {
3370 $this->
DebugMessage(@$ImageCreateFromFunctionName.
'() was attempted but FAILED', __FILE__, __LINE__);
3372 $this->
DebugMessage(
'Populating $rawimagedata', __FILE__, __LINE__);
3374 if ($fp = @fopen($filename,
'rb')) {
3375 $filesize = filesize($filename);
3377 $blockreads = ceil($filesize / $blocksize);
3378 for (
$i = 0;
$i < $blockreads;
$i++) {
3379 $rawimagedata .= fread($fp, $blocksize);
3383 $this->
DebugMessage(
'cannot fopen('.$filename.
')', __FILE__, __LINE__);
3385 if ($rawimagedata) {
3386 $this->
DebugMessage(
'attempting ImageCreateFromStringReplacement($rawimagedata ('.strlen($rawimagedata).
' bytes), true)', __FILE__, __LINE__);
3394 if (is_resource($this->gdimg_source)) {
3395 $this->source_width = ImageSX($this->gdimg_source);
3396 $this->source_height = ImageSY($this->gdimg_source);
3397 $this->
DebugMessage(
'skipping SourceImageToGD() because $this->gdimg_source is already a resource ('.$this->source_width.
'x'.$this->source_height.
')', __FILE__, __LINE__);
3400 $this->
DebugMessage(
'starting SourceImageToGD()', __FILE__, __LINE__);
3402 if ($this->config_prefer_imagemagick) {
3403 if (empty($this->sourceFilename) && !empty($this->rawImageData)) {
3404 $this->
DebugMessage(
'Copying raw image data to temp file and trying again with ImageMagick', __FILE__, __LINE__);
3406 if (file_put_contents($tempname, $this->rawImageData)) {
3407 $this->sourceFilename = $tempnam;
3410 $this->
DebugMessage(
'ImageMagickThumbnailToGD() succeeded', __FILE__, __LINE__);
3412 $this->
DebugMessage(
'ImageMagickThumbnailToGD() failed', __FILE__, __LINE__);
3415 $this->
DebugMessage(
'failed to put $this->rawImageData into temp file "'.$tempnam.
'"', __FILE__, __LINE__);
3418 $this->
DebugMessage(
'failed to generate temp file name', __FILE__, __LINE__);
3422 if (!$this->gdimg_source && $this->rawImageData) {
3425 $memory_get_usage = (function_exists(
'memory_get_usage') ? memory_get_usage() : 0);
3426 return $this->
ErrorImage(
'Source image is too large ('.$this->source_width.
'x'.$this->source_height.
' = '.number_format($this->source_width * $this->source_height / 1000000, 1).
'Mpx, max='.number_format($this->config_max_source_pixels / 1000000, 1).
'Mpx) for GD creation (either install ImageMagick or increase PHP memory_limit to at least '.ceil(($memory_get_usage + (5 * $this->source_width * $this->source_height)) / 1048576).
'M).');
3428 if ($this->md5s && ($this->md5s != md5($this->rawImageData))) {
3429 return $this->
ErrorImage(
'$this->md5s != md5($this->rawImageData)'.
"\n".
'"'.$this->md5s.
'" != '.
"\n".
'"'.md5($this->rawImageData).
'"');
3435 if (!$this->gdimg_source) {
3436 if (substr($this->rawImageData, 0, 2) ===
'BM') {
3437 $this->getimagesizeinfo[2] = 6;
3438 } elseif (substr($this->rawImageData, 0, 4) ===
'II'.
"\x2A\x00") {
3439 $this->getimagesizeinfo[2] = 7;
3440 } elseif (substr($this->rawImageData, 0, 4) ===
'MM'.
"\x00\x2A") {
3441 $this->getimagesizeinfo[2] = 8;
3443 $this->
DebugMessage(
'SourceImageToGD.ImageCreateFromStringReplacement() failed with unknown image type "'.substr($this->rawImageData, 0, 4).
'" ('.
phpthumb_functions::HexCharDisplay(substr($this->rawImageData, 0, 4)).
')', __FILE__, __LINE__);
3447 } elseif (!$this->gdimg_source && $this->sourceFilename) {
3452 switch (@$this->getimagesizeinfo[2]) {
3456 $this->is_alpha =
true;
3466 if ($this->gdimg_source) {
3467 $this->
DebugMessage(
'Not using EXIF thumbnail data because $this->gdimg_source is already set', __FILE__, __LINE__);
3470 if (!$this->exif_thumbnail_data) {
3471 $this->
DebugMessage(
'Not using EXIF thumbnail data because $this->exif_thumbnail_data is empty', __FILE__, __LINE__);
3474 if (ini_get(
'safe_mode')) {
3476 $this->
DebugMessage(
'Using EXIF thumbnail data because source image too large and safe_mode enabled', __FILE__, __LINE__);
3482 if (!$this->config_use_exif_thumbnail_for_speed) {
3483 $this->
DebugMessage(
'Not using EXIF thumbnail data because $this->config_use_exif_thumbnail_for_speed is FALSE', __FILE__, __LINE__);
3486 if (($this->thumbnailCropX != 0) || ($this->thumbnailCropY != 0)) {
3487 $this->
DebugMessage(
'Not using EXIF thumbnail data because source cropping is enabled ('.$this->thumbnailCropX.
','.$this->thumbnailCropY.
')', __FILE__, __LINE__);
3490 if (($this->w > $this->exif_thumbnail_width) || ($this->h > $this->exif_thumbnail_height)) {
3491 $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__);
3496 if (number_format($source_ar, 2) != number_format($exif_ar, 2)) {
3497 $this->
DebugMessage(
'not using EXIF thumbnail because $source_ar != $exif_ar ('.$source_ar.
' != '.$exif_ar.
')', __FILE__, __LINE__);
3503 $this->
DebugMessage(
'Trying to use EXIF thumbnail as source image', __FILE__, __LINE__);
3507 $this->
DebugMessage(
'Successfully using EXIF thumbnail as source image', __FILE__, __LINE__);
3508 $this->gdimg_source = $gdimg_exif_temp;
3516 $this->
DebugMessage(
'$this->ImageCreateFromStringReplacement($this->exif_thumbnail_data, false) failed', __FILE__, __LINE__);
3522 if (!$this->gdimg_source) {
3523 $this->
DebugMessage(
'$this->gdimg_source is still empty', __FILE__, __LINE__);
3525 $this->
DebugMessage(
'ImageMagickThumbnailToGD() failed', __FILE__, __LINE__);
3528 $gd_info = gd_info();
3529 $GDreadSupport =
false;
3530 switch (@$this->getimagesizeinfo[2]) {
3532 $imageHeader =
'Content-Type: image/gif';
3533 $GDreadSupport = (bool) @$gd_info[
'GIF Read Support'];
3536 $imageHeader =
'Content-Type: image/jpeg';
3537 $GDreadSupport = (bool) @$gd_info[
'JPG Support'];
3540 $imageHeader =
'Content-Type: image/png';
3541 $GDreadSupport = (bool) @$gd_info[
'PNG Support'];
3547 if ($this->config_error_die_on_source_failure) {
3548 $errormessages = array();
3549 $errormessages[] =
'All attempts to create GD image source failed.';
3550 if ($this->fatalerror) {
3553 if ($this->issafemode) {
3554 $errormessages[] =
'Safe Mode enabled, therefore ImageMagick is unavailable. (disable Safe Mode if possible)';
3556 $errormessages[] =
'ImageMagick is not installed (it is highly recommended that you install it).';
3559 $memory_get_usage = (function_exists(
'memory_get_usage') ? memory_get_usage() : 0);
3560 $errormessages[] =
'Source image is too large ('.$this->getimagesizeinfo[0].
'x'.$this->getimagesizeinfo[1].
' = '.number_format($this->getimagesizeinfo[0] * $this->getimagesizeinfo[1] / 1000000, 1).
'Mpx, max='.number_format($this->config_max_source_pixels / 1000000, 1).
'Mpx) for GD creation (either install ImageMagick or increase PHP memory_limit to at least '.ceil(($memory_get_usage + (5 * $this->getimagesizeinfo[0] * $this->getimagesizeinfo[1])) / 1048576).
'M).';
3561 } elseif (!$GDreadSupport) {
3562 $errormessages[] =
'GD does not have read support for "'.$imageHeader.
'".';
3564 $errormessages[] =
'Source image probably corrupt.';
3566 $this->
ErrorImage(implode(
"\n", $errormessages));
3569 $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');
3582 switch (@$this->getimagesizeinfo[2]) {
3585 if (!@include_once(dirname(__FILE__).
'/phpthumb.bmp.php')) {
3587 return $this->
ErrorImage(
'include_once('.dirname(__FILE__).
'/phpthumb.bmp.php) failed');
3590 if ($fp = @fopen($this->sourceFilename,
'rb')) {
3591 $this->rawImageData =
'';
3592 while (!feof($fp)) {
3593 $this->rawImageData .= fread($fp, 32768);
3599 unset($phpthumb_bmp);
3600 if ($this->gdimg_source) {
3601 $this->
DebugMessage(
'$phpthumb_bmp->phpthumb_bmp2gd() succeeded', __FILE__, __LINE__);
3612 return $this->
ErrorImage($this->
ImageMagickVersion() ?
'ImageMagick failed on TIFF source conversion' :
'ImageMagick is unavailable and phpThumb() does not support TIFF source images without it');
3620 if (!$this->gdimg_source) {
3621 $HeaderFourBytes =
'';
3622 if ($this->rawImageData) {
3623 $HeaderFourBytes = substr($this->rawImageData, 0, 4);
3624 } elseif ($this->sourceFilename) {
3625 if ($fp = @fopen($this->sourceFilename,
'rb')) {
3626 $HeaderFourBytes = fread($fp, 4);
3629 return $this->
ErrorImage(
'failed to open "'.$this->sourceFilename.
'" SourceImageToGD() ['.__LINE__.
']');
3632 return $this->
ErrorImage(
'Unable to create image, neither filename nor image data suppplied in SourceImageToGD() ['.__LINE__.
']');
3635 return $this->
ErrorImage(
'Neither GD nor ImageMagick seem to be installed on this server. At least one (preferably GD), or better both, MUST be installed for phpThumb to work.');
3636 } elseif ($HeaderFourBytes ==
"\xD7\xCD\xC6\x9A") {
3637 return $this->
ErrorImage($this->
ImageMagickVersion() ?
'ImageMagick failed on WMF source conversion' :
'ImageMagick is unavailable and phpThumb() does not support WMF source images without it');
3638 } elseif ($HeaderFourBytes ==
'%PDF') {
3639 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');
3640 } elseif (substr($HeaderFourBytes, 0, 3) ==
"\xFF\xD8\xFF") {
3641 return $this->
ErrorImage(
'Image (JPEG) is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
3642 } elseif ($HeaderFourBytes ==
'%PNG') {
3643 return $this->
ErrorImage(
'Image (PNG) is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
3644 } elseif (substr($HeaderFourBytes, 0, 3) ==
'GIF') {
3645 return $this->
ErrorImage(
'Image (GIF) is too large for PHP-GD memory_limit, please install ImageMagick or increase php.ini memory_limit setting');
3651 if (!$this->gdimg_source) {
3653 $this->
DebugMessage(
'All other attempts failed, but successfully using EXIF thumbnail as source image', __FILE__, __LINE__);
3654 $this->gdimg_source = $gdimg_exif_temp;
3663 $this->source_width = ImageSX($this->gdimg_source);
3664 $this->source_height = ImageSY($this->gdimg_source);
3670 if (is_null(
$var)) {
3672 } elseif (is_bool(
$var)) {
3673 return (
$var ?
'TRUE' :
'FALSE');
3674 } elseif (is_string(
$var)) {
3675 return 'string('.strlen(
$var).
')'.str_repeat(
' ', max(0, 3 - strlen(strlen(
$var)))).
' "'.
$var.
'"';
3676 } elseif (is_int(
$var)) {
3677 return 'integer '.$var;
3678 } elseif (is_float(
$var)) {
3679 return 'float '.$var;
3680 } elseif (is_array(
$var)) {
3683 $vardumpoutput = ob_get_contents();
3685 return strtr($vardumpoutput,
"\n\r\t",
' ');
3687 return gettype(
$var);
3694 if ($this->config_disable_debug) {
3695 return $this->
ErrorImage(
'phpThumbDebug disabled');
3698 $FunctionsExistance = array(
'exif_thumbnail',
'gd_info',
'image_type_to_mime_type',
'GetImageSize',
'ImageCopyResampled',
'ImageCopyResized',
'ImageCreate',
'ImageCreateFromString',
'ImageCreateTrueColor',
'ImageIsTrueColor',
'ImageRotate',
'ImageTypes',
'version_compare',
'ImageCreateFromGIF',
'ImageCreateFromJPEG',
'ImageCreateFromPNG',
'ImageCreateFromWBMP',
'ImageCreateFromXBM',
'ImageCreateFromXPM',
'ImageCreateFromString',
'ImageCreateFromGD',
'ImageCreateFromGD2',
'ImageCreateFromGD2Part',
'ImageJPEG',
'ImageGIF',
'ImagePNG',
'ImageWBMP');
3699 $ParameterNames = array(
'src',
'new',
'w',
'h',
'f',
'q',
'sx',
'sy',
'sw',
'sh',
'far',
'bg',
'bc',
'file',
'goto',
'err',
'xto',
'ra',
'ar',
'aoe',
'iar',
'maxb');
3700 $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',
'max_source_pixels',
'use_exif_thumbnail_for_speed',
'border_hexcolor',
'background_hexcolor',
'ttf_directory',
'disable_pathinfo_parsing',
'disable_imagecopyresampled');
3701 $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');
3703 $DebugOutput = array();
3704 $DebugOutput[] =
'phpThumb() version = '.$this->phpthumb_version;
3705 $DebugOutput[] =
'phpversion() = '.@phpversion();
3706 $DebugOutput[] =
'PHP_OS = '.PHP_OS;
3707 $DebugOutput[] =
'$_SERVER[SERVER_SOFTWARE] = '.@
$_SERVER[
'SERVER_SOFTWARE'];
3708 $DebugOutput[] =
'__FILE__ = '.__FILE__;
3709 $DebugOutput[] =
'realpath(.) = '.@realpath(
'.');
3710 $DebugOutput[] =
'$_SERVER[PHP_SELF] = '.@
$_SERVER[
'PHP_SELF'];
3711 $DebugOutput[] =
'$_SERVER[HOST_NAME] = '.@
$_SERVER[
'HOST_NAME'];
3712 $DebugOutput[] =
'$_SERVER[HTTP_REFERER] = '.@
$_SERVER[
'HTTP_REFERER'];
3713 $DebugOutput[] =
'$_SERVER[QUERY_STRING] = '.@
$_SERVER[
'QUERY_STRING'];
3714 $DebugOutput[] =
'$_SERVER[PATH_INFO] = '.@
$_SERVER[
'PATH_INFO'];
3715 $DebugOutput[] =
'$_SERVER[DOCUMENT_ROOT] = '.@
$_SERVER[
'DOCUMENT_ROOT'];
3716 $DebugOutput[] =
'getenv(DOCUMENT_ROOT) = '.@getenv(
'DOCUMENT_ROOT');
3717 $DebugOutput[] =
'';
3719 $DebugOutput[] =
'get_magic_quotes_gpc() = '.$this->phpThumbDebugVarDump(@get_magic_quotes_gpc());
3720 $DebugOutput[] =
'get_magic_quotes_runtime() = '.$this->phpThumbDebugVarDump(@get_magic_quotes_runtime());
3721 $DebugOutput[] =
'error_reporting() = '.$this->phpThumbDebugVarDump(error_reporting());
3722 $DebugOutput[] =
'ini_get(error_reporting) = '.$this->phpThumbDebugVarDump(@ini_get(
'error_reporting'));
3723 $DebugOutput[] =
'ini_get(display_errors) = '.$this->phpThumbDebugVarDump(@ini_get(
'display_errors'));
3724 $DebugOutput[] =
'ini_get(allow_url_fopen) = '.$this->phpThumbDebugVarDump(@ini_get(
'allow_url_fopen'));
3725 $DebugOutput[] =
'ini_get(disable_functions) = '.$this->phpThumbDebugVarDump(@ini_get(
'disable_functions'));
3726 $DebugOutput[] =
'get_cfg_var(disable_functions) = '.$this->phpThumbDebugVarDump(@get_cfg_var(
'disable_functions'));
3727 $DebugOutput[] =
'ini_get(safe_mode) = '.$this->phpThumbDebugVarDump(@ini_get(
'safe_mode'));
3728 $DebugOutput[] =
'ini_get(open_basedir) = '.$this->phpThumbDebugVarDump(@ini_get(
'open_basedir'));
3729 $DebugOutput[] =
'ini_get(max_execution_time) = '.$this->phpThumbDebugVarDump(@ini_get(
'max_execution_time'));
3730 $DebugOutput[] =
'ini_get(memory_limit) = '.$this->phpThumbDebugVarDump(@ini_get(
'memory_limit'));
3731 $DebugOutput[] =
'get_cfg_var(memory_limit) = '.$this->phpThumbDebugVarDump(@get_cfg_var(
'memory_limit'));
3732 $DebugOutput[] =
'memory_get_usage() = '.(function_exists(
'memory_get_usage') ? $this->
phpThumbDebugVarDump(@memory_get_usage()) :
'n/a');
3733 $DebugOutput[] =
'';
3735 $DebugOutput[] =
'$this->config_prefer_imagemagick = '.$this->phpThumbDebugVarDump($this->config_prefer_imagemagick);
3736 $DebugOutput[] =
'$this->config_imagemagick_path = '.$this->phpThumbDebugVarDump($this->config_imagemagick_path);
3737 $DebugOutput[] =
'$this->ImageMagickWhichConvert() = '.$this->ImageMagickWhichConvert();
3738 $IMpathUsed = ($this->config_imagemagick_path ? $this->config_imagemagick_path : $this->
ImageMagickWhichConvert());
3739 $DebugOutput[] =
'[actual ImageMagick path used] = '.$this->phpThumbDebugVarDump($IMpathUsed);
3740 $DebugOutput[] =
'file_exists([actual ImageMagick path used]) = '.$this->phpThumbDebugVarDump(@file_exists($IMpathUsed));
3741 $DebugOutput[] =
'ImageMagickVersion(false) = '.$this->ImageMagickVersion(
false);
3742 $DebugOutput[] =
'ImageMagickVersion(true) = '.$this->ImageMagickVersion(
true);
3743 $DebugOutput[] =
'';
3745 $DebugOutput[] =
'$this->config_cache_directory = '.$this->phpThumbDebugVarDump($this->config_cache_directory);
3746 $DebugOutput[] =
'$this->config_cache_directory_depth = '.$this->phpThumbDebugVarDump($this->config_cache_directory_depth);
3747 $DebugOutput[] =
'$this->config_cache_disable_warning = '.$this->phpThumbDebugVarDump($this->config_cache_disable_warning);
3748 $DebugOutput[] =
'$this->config_cache_maxage = '.$this->phpThumbDebugVarDump($this->config_cache_maxage);
3749 $DebugOutput[] =
'$this->config_cache_maxsize = '.$this->phpThumbDebugVarDump($this->config_cache_maxsize);
3750 $DebugOutput[] =
'$this->config_cache_maxfiles = '.$this->phpThumbDebugVarDump($this->config_cache_maxfiles);
3751 $DebugOutput[] =
'$this->config_cache_force_passthru = '.$this->phpThumbDebugVarDump($this->config_cache_force_passthru);
3752 $DebugOutput[] =
'$this->cache_filename = '.$this->phpThumbDebugVarDump($this->cache_filename);
3753 $DebugOutput[] =
'is_readable($this->config_cache_directory) = '.$this->phpThumbDebugVarDump(@is_readable($this->config_cache_directory));
3754 $DebugOutput[] =
'is_writable($this->config_cache_directory) = '.$this->phpThumbDebugVarDump(@is_writable($this->config_cache_directory));
3755 $DebugOutput[] =
'is_readable($this->cache_filename) = '.$this->phpThumbDebugVarDump(@is_readable($this->cache_filename));
3756 $DebugOutput[] =
'is_writable($this->cache_filename) = '.(@file_exists($this->cache_filename) ? $this->
phpThumbDebugVarDump(@is_writable($this->cache_filename)) :
'n/a');
3757 $DebugOutput[] =
'';
3759 foreach ($ConfigVariableNames as $varname) {
3760 $varname =
'config_'.$varname;
3761 $value = $this->$varname;
3762 $DebugOutput[] =
'$this->'.str_pad($varname, 37,
' ', STR_PAD_RIGHT).
' = '.$this->
phpThumbDebugVarDump($value);
3764 $DebugOutput[] =
'';
3765 foreach ($OtherVariableNames as $varname) {
3766 $value = $this->$varname;
3767 $DebugOutput[] =
'$this->'.str_pad($varname, 27,
' ', STR_PAD_RIGHT).
' = '.$this->
phpThumbDebugVarDump($value);
3769 $DebugOutput[] =
'strlen($this->rawImageData) = '.strlen(@$this->rawImageData);
3770 $DebugOutput[] =
'strlen($this->exif_thumbnail_data) = '.strlen(@$this->exif_thumbnail_data);
3771 $DebugOutput[] =
'';
3773 foreach ($ParameterNames as $varname) {
3774 $value = $this->$varname;
3775 $DebugOutput[] =
'$this->'.str_pad($varname, 4,
' ', STR_PAD_RIGHT).
' = '.$this->
phpThumbDebugVarDump($value);
3777 $DebugOutput[] =
'';
3779 foreach ($FunctionsExistance as $functionname) {
3782 $DebugOutput[] =
'';
3784 $gd_info = gd_info();
3785 foreach ($gd_info as $key => $value) {
3786 $DebugOutput[] =
'gd_info.'.str_pad($key, 34,
' ', STR_PAD_RIGHT).
' = '.$this->
phpThumbDebugVarDump($value);
3788 $DebugOutput[] =
'';
3791 foreach ($exif_info as $key => $value) {
3792 $DebugOutput[] =
'exif_info.'.str_pad($key, 26,
' ', STR_PAD_RIGHT).
' = '.$this->
phpThumbDebugVarDump($value);
3794 $DebugOutput[] =
'';
3797 foreach ($ApacheLookupURIarray as $key => $value) {
3798 $DebugOutput[] =
'ApacheLookupURIarray.'.str_pad($key, 15,
' ', STR_PAD_RIGHT).
' = '.$this->
phpThumbDebugVarDump($value);
3801 $DebugOutput[] =
'ApacheLookupURIarray() -- FAILED';
3803 $DebugOutput[] =
'';
3806 foreach (
$_GET as $key => $value) {
3807 $DebugOutput[] =
'$_GET['.$key.
']'.str_repeat(
' ', 30 - strlen($key)).
'= '.$this->
phpThumbDebugVarDump($value);
3811 foreach (
$_POST as $key => $value) {
3812 $DebugOutput[] =
'$_POST['.$key.
']'.str_repeat(
' ', 29 - strlen($key)).
'= '.$this->
phpThumbDebugVarDump($value);
3815 $DebugOutput[] =
'';
3817 $DebugOutput[] =
'$this->debugmessages:';
3818 foreach ($this->debugmessages as $errorstring) {
3819 $DebugOutput[] =
' * '.$errorstring;
3821 $DebugOutput[] =
'';
3823 $DebugOutput[] =
'$this->debugtiming:';
3824 foreach ($this->debugtiming as $timestamp => $timingstring) {
3825 $DebugOutput[] =
' * '.$timestamp.
' '.$timingstring;
3827 $DebugOutput[] =
' * Total processing time: '.number_format(max(array_keys($this->debugtiming)) - min(array_keys($this->debugtiming)), 6);
3830 return $this->
ErrorImage(implode(
"\n", $DebugOutput), 700, 500,
true);
3834 if (is_null($this->fatalerror)) {
3835 $this->fatalerror = $text;
3840 function ErrorImage($text, $width=0, $height=0, $forcedisplay=
false) {
3844 $text =
'phpThumb() v'.$this->phpthumb_version.
"\n".
'http://phpthumb.sourceforge.net'.
"\n\n".($this->config_disable_debug ?
'Error messages disabled' : $text);
3852 if (!$this->config_error_die_on_error && !$forcedisplay) {
3855 if ($this->config_error_silent_die_on_error) {
3858 if ($this->err || $this->config_error_message_image_default) {
3864 header(
'Location: '.($this->err ? $this->err : $this->config_error_message_image_default));
3870 $this->thumbnailFormat =
'text';
3872 if (@$this->thumbnailFormat ==
'text') {
3874 if (!headers_sent()) {
3875 header(
'Content-type: text/plain');
3878 echo
'<pre>'.htmlspecialchars($text).
'</pre>';
3883 $FontWidth = ImageFontWidth($this->config_error_fontsize);
3884 $FontHeight = ImageFontHeight($this->config_error_fontsize);
3886 $LinesOfText = explode(
"\n", @wordwrap($text, floor($width / $FontWidth),
"\n",
true));
3887 $height = max($height, count($LinesOfText) * $FontHeight);
3893 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>';
3895 } elseif (headers_sent()) {
3897 echo
"\n".
'**Headers already sent, dumping error message as text:**<br><pre>'.
"\n\n".$text.
"\n".
'</pre>';
3899 } elseif ($gdimg_error = ImageCreate($width, $height)) {
3903 ImageFilledRectangle($gdimg_error, 0, 0, $width, $height, $background_color);
3905 foreach ($LinesOfText as $line) {
3906 ImageString($gdimg_error, $this->config_error_fontsize, 2, $lineYoffset, $line, $text_color);
3907 $lineYoffset += $FontHeight;
3909 if (function_exists(
'ImageTypes')) {
3910 $imagetypes = ImageTypes();
3911 if ($imagetypes & IMG_PNG) {
3912 header(
'Content-Type: image/png');
3913 ImagePNG($gdimg_error);
3914 } elseif ($imagetypes & IMG_GIF) {
3915 header(
'Content-Type: image/gif');
3916 ImageGIF($gdimg_error);
3917 } elseif ($imagetypes & IMG_JPG) {
3918 header(
'Content-Type: image/jpeg');
3919 ImageJPEG($gdimg_error);
3920 } elseif ($imagetypes & IMG_WBMP) {
3921 header(
'Content-Type: image/vnd.wap.wbmp');
3922 ImageWBMP($gdimg_error);
3925 ImageDestroy($gdimg_error);
3928 if (!headers_sent()) {
3929 echo
"\n".
'**Failed to send graphical error image, dumping error message as text:**<br>'.
"\n\n".$text;
3941 if (!headers_sent()) {
3943 $ERROR_NOGD =
'R0lGODlhIAAgALMAAAAAABQUFCQkJDY2NkZGRldXV2ZmZnJycoaGhpSUlKWlpbe3t8XFxdXV1eTk5P7+/iwAAAAAIAAgAAAE/vDJSau9WILtTAACUinDNijZtAHfCojS4W5H+qxD8xibIDE9h0OwWaRWDIljJSkUJYsN4bihMB8th3IToAKs1VtYM75cyV8sZ8vygtOE5yMKmGbO4jRdICQCjHdlZzwzNW4qZSQmKDaNjhUMBX4BBAlmMywFSRWEmAI6b5gAlhNxokGhooAIK5o/pi9vEw4Lfj4OLTAUpj6IabMtCwlSFw0DCKBoFqwAB04AjI54PyZ+yY3TD0ss2YcVmN/gvpcu4TOyFivWqYJlbAHPpOntvxNAACcmGHjZzAZqzSzcq5fNjxFmAFw9iFRunD1epU6tsIPmFCAJnWYE0FURk7wJDA0MTKpEzoWAAskiAAA7';
3944 header(
'Content-Type: image/gif');
3945 echo base64_decode($ERROR_NOGD);
3947 echo
'*** ERROR: No PHP-GD support available ***';
3956 $this->
DebugMessage(
'ImageCreateFromStringReplacement() calling built-in ImageCreateFromString()', __FILE__, __LINE__);
3957 return @ImageCreateFromString($RawImageData);
3959 if ($this->issafemode) {
3960 $this->
DebugMessage(
'ImageCreateFromStringReplacement() failed: cannot create temp file in SAFE_MODE', __FILE__, __LINE__);
3964 switch (substr($RawImageData, 0, 3)) {
3966 $ICFSreplacementFunctionName =
'ImageCreateFromGIF';
3968 case "\xFF\xD8\xFF":
3969 $ICFSreplacementFunctionName =
'ImageCreateFromJPEG';
3972 $ICFSreplacementFunctionName =
'ImageCreateFromPNG';
3980 if ($fp_tempnam = @fopen($tempnam,
'wb')) {
3981 fwrite($fp_tempnam, $RawImageData);
3982 fclose($fp_tempnam);
3983 if (($ICFSreplacementFunctionName ==
'ImageCreateFromGIF') && !function_exists($ICFSreplacementFunctionName)) {
3987 if (!@include_once(dirname(__FILE__).
'/phpthumb.gif.php')) {
3988 $ErrorMessage =
'Failed to include required file "'.dirname(__FILE__).
'/phpthumb.gif.php" in '.__FILE__.
' on line '.__LINE__;
3989 $this->
DebugMessage($ErrorMessage, __FILE__, __LINE__);
3994 if ($fp_tempfile = @fopen($tempfilename,
'wb')) {
3995 fwrite($fp_tempfile, $RawImageData);
3996 fclose($fp_tempfile);
3998 $this->
DebugMessage(
'gif_loadFileToGDimageResource('.$tempfilename.
') completed', __FILE__, __LINE__);
3999 $this->
DebugMessage(
'deleting "'.$tempfilename.
'"', __FILE__, __LINE__);
4000 unlink($tempfilename);
4004 $ErrorMessage =
'Failed to open tempfile in '.__FILE__.
' on line '.__LINE__;
4005 $this->
DebugMessage($ErrorMessage, __FILE__, __LINE__);
4008 $ErrorMessage =
'Failed to open generate tempfile name in '.__FILE__.
' on line '.__LINE__;
4009 $this->
DebugMessage($ErrorMessage, __FILE__, __LINE__);
4012 } elseif (function_exists($ICFSreplacementFunctionName) && (
$gdimg_source = @$ICFSreplacementFunctionName($tempnam))) {
4015 $this->
DebugMessage($ICFSreplacementFunctionName.
'('.$tempnam.
') succeeded', __FILE__, __LINE__);
4016 $this->
DebugMessage(
'deleting "'.$tempnam.
'"', __FILE__, __LINE__);
4023 $this->
DebugMessage($ICFSreplacementFunctionName.
'('.$tempnam.
') '.(function_exists($ICFSreplacementFunctionName) ?
'failed' :
'does not exist'), __FILE__, __LINE__);
4024 if (isset(
$_GET[
'phpThumbDebug'])) {
4030 $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';
4031 if ($this->issafemode) {
4032 $ErrorMessage =
'ImageCreateFromStringReplacement() failed in '.__FILE__.
' on line '.__LINE__.
': cannot create temp file in SAFE_MODE';
4034 $this->
DebugMessage($ErrorMessage, __FILE__, __LINE__);
4036 $this->
DebugMessage(
'deleting "'.$tempnam.
'"', __FILE__, __LINE__);
4039 $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';
4040 if ($this->issafemode) {
4041 $ErrorMessage =
'ImageCreateFromStringReplacement() failed in '.__FILE__.
' on line '.__LINE__.
': cannot create temp file in SAFE_MODE';
4044 if ($DieOnErrors && $ErrorMessage) {
4051 $this->
DebugMessage(
'ImageResizeFunction($o, $s, '.$dstX.
', '.$dstY.
', '.$srcX.
', '.$srcY.
', '.$dstW.
', '.$dstH.
', '.$srcW.
', '.$srcH.
')', __FILE__, __LINE__);
4052 if (($dstW == $srcW) && ($dstH == $srcH)) {
4053 return ImageCopy($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $srcW, $srcH);
4056 if ($this->config_disable_imagecopyresampled) {
4059 return ImageCopyResampled($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
4061 return ImageCopyResized($dst_im, $src_im, $dstX, $dstY, $srcX, $srcY, $dstW, $dstH, $srcW, $srcH);
4065 $this->config_temp_directory = realpath($this->config_temp_directory ? $this->config_temp_directory : (getenv(
'TMPDIR') ? getenv(
'TMPDIR') : getenv(
'TMP')));
4071 $tempnam = realpath(tempnam($this->config_temp_directory,
'pThumb'));
4072 $this->tempFilesToDelete[$tempnam] = $tempnam;
4073 $this->
DebugMessage(
'phpThumb_tempnam() returning "'.$tempnam.
'"', __FILE__, __LINE__);
4078 $this->debugmessages[] = $message.($file ?
' in file "'.(basename(
$file) ? basename(
$file) :
$file).
'"' :
'').($line ?
' on line '.$line :
'');
4084 $timestamp = array_sum(explode(
' ', microtime()));
4086 $this->debugtiming[number_format($timestamp, 6,
'.',
'')] =
': '.$message.($file ?
' in file "'.(basename(
$file) ? basename(
$file) :
$file).
'"' :
'').($line ?
' on line '.$line :
'');