Skip to content

Commit

Permalink
Merge pull request #854 from mambax7/feature/phpthumb_1.7.16-20200810…
Browse files Browse the repository at this point in the history
…1454

latest changes from https://github.com/JamesHeinrich/phpThumb
  • Loading branch information
geekwright committed Aug 16, 2020
2 parents 79149cd + ec024f6 commit dd37f90
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 15 deletions.
1 change: 1 addition & 0 deletions docs/changelog.250.txt
Expand Up @@ -50,6 +50,7 @@ Updated libraries and assets:
- HTML Purifier to 4.12 (mamba)
- phpmailer to 5.2.27 (mamba)
- jQuery to 3.4.1 (mamba)
- phpThumb to 1.7.16-202008101454 (mamba)

===================================
2.5.10 Final 2019/04/29
Expand Down
12 changes: 6 additions & 6 deletions htdocs/modules/system/class/thumbs/phpThumb.php
Expand Up @@ -387,7 +387,7 @@ function RedirectToCachedFile() {
$PHPTHUMB_DEFAULTS_DISABLEGETPARAMS = (bool) ($phpThumb->config_cache_default_only_suffix && (strpos($phpThumb->config_cache_default_only_suffix, '*') !== false));

// deprecated: 'err', 'file', 'goto',
$allowedGETparameters = array('src', 'new', 'w', 'h', 'wp', 'hp', 'wl', 'hl', 'ws', 'hs', 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'zc', 'bc', 'bg', 'bgt', 'fltr', 'xto', 'ra', 'ar', 'aoe', 'far', 'iar', 'maxb', 'down', 'phpThumbDebug', 'hash', 'md5s', 'sfn', 'dpi', 'sia', 'nocache');
$allowedGETparameters = array('src', 'new', 'w', 'h', 'wp', 'hp', 'wl', 'hl', 'ws', 'hs', 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'zc', 'ica', 'bc', 'bg', 'bgt', 'fltr', 'xto', 'ra', 'ar', 'aoe', 'far', 'iar', 'maxb', 'down', 'phpThumbDebug', 'hash', 'md5s', 'sfn', 'dpi', 'sia', 'nocache');
foreach ($_GET as $key => $value) {
if (!empty($PHPTHUMB_DEFAULTS_DISABLEGETPARAMS) && ($key != 'src')) {
// disabled, do not set parameter
Expand Down Expand Up @@ -436,10 +436,10 @@ function RedirectToCachedFile() {
$CanPassThroughDirectly = true;
if ($phpThumb->rawImageData) {
// data from SQL, should be fine
} elseif (preg_match('#^http\://[^\\?&]+\\.(jpe?g|gif|png|webp)$#i', $phpThumb->src)) {
} elseif (preg_match('#^https?\\://[^\\?&]+\\.(jpe?g|gif|png|webp)$#i', $phpThumb->src)) {
// assume is ok to passthru if no other parameters specified
} elseif (preg_match('#^(f|ht)tp\://#i', $phpThumb->src)) {
$phpThumb->DebugMessage('$CanPassThroughDirectly=false because preg_match("#^(f|ht)tp\://#i", '.$phpThumb->src.')', __FILE__, __LINE__);
} elseif (preg_match('#^(f|ht)tps?\\://#i', $phpThumb->src)) {
$phpThumb->DebugMessage('$CanPassThroughDirectly=false because preg_match("#^(f|ht)tps?://#i", '.$phpThumb->src.')', __FILE__, __LINE__);
$CanPassThroughDirectly = false;
} elseif (!@is_readable($phpThumb->sourceFilename)) {
$phpThumb->DebugMessage('$CanPassThroughDirectly=false because !@is_readable('.$phpThumb->sourceFilename.')', __FILE__, __LINE__);
Expand All @@ -457,7 +457,7 @@ function RedirectToCachedFile() {
case 'w':
case 'h':
// might be OK if exactly matches original
if (preg_match('#^http\://[^\\?&]+\\.(jpe?g|gif|png|webp)$#i', $phpThumb->src)) {
if (preg_match('#^https?\\://[^\\?&]+\\.(jpe?g|gif|png|webp)$#i', $phpThumb->src)) {
// assume it is not ok for direct-passthru of remote image
$CanPassThroughDirectly = false;
}
Expand Down Expand Up @@ -491,7 +491,7 @@ function RedirectToCachedFile() {
while ($CanPassThroughDirectly && $phpThumb->src) {
// no parameters set, passthru

if (preg_match('#^http\://[^\\?&]+\.(jpe?g|gif|png|webp)$#i', $phpThumb->src)) {
if (preg_match('#^https?\\://[^\\?&]+\.(jpe?g|gif|png|webp)$#i', $phpThumb->src)) {
$phpThumb->DebugMessage('Passing HTTP source through directly as Location: redirect ('.$phpThumb->src.')', __FILE__, __LINE__);
header('Location: '.$phpThumb->src);
exit;
Expand Down
83 changes: 74 additions & 9 deletions htdocs/modules/system/class/thumbs/phpthumb.class.php
Expand Up @@ -42,6 +42,7 @@ class phpthumb {
public $sw = null; // Source crop Width
public $sh = null; // Source crop Height
public $zc = null; // Zoom Crop
public $ica = null; // Image Crop Auto
public $bc = null; // Border Color
public $bg = null; // BackGround color
public $fltr = array(); // FiLTeRs
Expand Down Expand Up @@ -219,7 +220,7 @@ class phpthumb {
public $issafemode = null;
public $php_memory_limit = null;

public $phpthumb_version = '1.7.15-202004301145';
public $phpthumb_version = '1.7.16-202008101454';

//////////////////////////////////////////////////////////////////////

Expand All @@ -233,7 +234,7 @@ public function phpThumb() {
$this->DebugMessage('phpThumb() v'.$this->phpthumb_version, __FILE__, __LINE__);

foreach (array(ini_get('memory_limit'), get_cfg_var('memory_limit')) as $php_config_memory_limit) {
if ('' !== $php_config_memory_limit) {
if (!empty($php_config_memory_limit)) {
if (strtoupper($php_config_memory_limit[ strlen($php_config_memory_limit) - 1 ]) == 'G') { // PHP memory limit expressed in Gigabytes
$php_config_memory_limit = (int) substr($php_config_memory_limit, 0, -1) * 1073741824;
} elseif (strtoupper($php_config_memory_limit[ strlen($php_config_memory_limit) - 1 ]) == 'M') { // PHP memory limit expressed in Megabytes
Expand Down Expand Up @@ -379,10 +380,12 @@ public function GenerateThumbnail() {
return false;
}
$this->phpThumbDebug('8f');
$this->ImageCropAuto();
$this->phpThumbDebug('8h');
$this->Rotate();
$this->phpThumbDebug('8g');
$this->CreateGDoutput();
$this->phpThumbDebug('8h');
$this->CreateGDoutput();
$this->phpThumbDebug('8i');

// default values, also applicable for far="C"
$destination_offset_x = round(($this->thumbnail_width - $this->thumbnail_image_width) / 2);
Expand Down Expand Up @@ -1043,7 +1046,7 @@ public function setOutputFormat() {
public function setCacheDirectory() {
// resolve cache directory to absolute pathname
$this->DebugMessage('setCacheDirectory() starting with config_cache_directory = "'.$this->config_cache_directory.'"', __FILE__, __LINE__);
if ($this->config_cache_directory[ 0 ] == '.') {
if ($this->config_cache_directory && ($this->config_cache_directory[0] == '.')) {
if (preg_match('#^(f|ht)tps?\://#i', $this->src)) {
if (!$this->config_cache_disable_warning) {
$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');
Expand Down Expand Up @@ -1620,6 +1623,16 @@ public function ImageMagickThumbnailToGD() {
if (phpthumb_functions::gd_version()) {
// if GD is not available, must use whatever ImageMagick can output

// $CannotMagickParameters contains options that cannot be used with ImageMagick
$CannotMagickParameters = array('ica');
foreach ($CannotMagickParameters as $parameter) {
if (isset($this->$parameter)) {
$this->DebugMessage('cannot process with ImageMagick because "'.$parameter.'" is set', __FILE__, __LINE__);
$this->useRawIMoutput = false;
return false;
}
}

// $UnAllowedParameters contains options that can only be processed in GD, not ImageMagick
// note: 'fltr' *may* need to be processed by GD, but we'll check that in more detail below
$UnAllowedParameters = array('xto', 'ar', 'bg', 'bc');
Expand Down Expand Up @@ -3393,10 +3406,13 @@ public function ExtractEXIFgetImageSize() {
}
if (null === $this->getimagesizeinfo) {
if ($this->sourceFilename) {
$this->getimagesizeinfo = @getimagesize($this->sourceFilename);
if ($this->getimagesizeinfo = @getimagesize($this->sourceFilename)) {
$this->source_width = $this->getimagesizeinfo[0];
$this->source_height = $this->getimagesizeinfo[1];
$this->DebugMessage('getimagesize('.$this->sourceFilename.') says image is '.$this->source_width.'x'.$this->source_height, __FILE__, __LINE__);
} else {
$this->DebugMessage('getimagesize('.$this->sourceFilename.') failed', __FILE__, __LINE__);
}
} else {
$this->DebugMessage('skipping getimagesize() because $this->sourceFilename is empty', __FILE__, __LINE__);
}
Expand Down Expand Up @@ -3435,21 +3451,23 @@ public function ExtractEXIFgetImageSize() {
$this->DebugMessage('ImageMagickThumbnailToGD() failed', __FILE__, __LINE__);
}

if (isset($this->getimagesizeinfo[1])) {
$this->source_width = $this->getimagesizeinfo[0];
$this->source_height = $this->getimagesizeinfo[1];
}

$this->SetOrientationDependantWidthHeight();

if (phpthumb_functions::version_compare_replacement(PHP_VERSION, '4.2.0', '>=') && function_exists('exif_read_data')) {
switch ($this->getimagesizeinfo[2]) {
switch (@$this->getimagesizeinfo[2]) {
case IMAGETYPE_JPEG:
case IMAGETYPE_TIFF_II:
case IMAGETYPE_TIFF_MM:
$this->exif_raw_data = @exif_read_data($this->sourceFilename, 0, true);
break;
}
}
if (function_exists('exif_thumbnail') && ($this->getimagesizeinfo[2] == IMAGETYPE_JPEG)) {
if (function_exists('exif_thumbnail') && (@$this->getimagesizeinfo[2] == IMAGETYPE_JPEG)) {
// Extract EXIF info from JPEGs

$this->exif_thumbnail_width = '';
Expand Down Expand Up @@ -3617,6 +3635,12 @@ public function SetCacheFilename() {
$ParametersString .= '_'.$key. (int) $this->$key;
}
}
$FilenameParameters3 = array('ica');
foreach ($FilenameParameters3 as $key) {
if ($this->$key) {
$ParametersString .= '_'.$key.substr(md5($this->$key), 0, 4);
}
}
if ($this->thumbnailFormat == 'jpeg') {
// only JPEG output has variable quality option
$ParametersString .= '_q'. (int) $this->thumbnailQuality;
Expand Down Expand Up @@ -4015,6 +4039,47 @@ public function SourceImageToGD() {
return true;
}

private function ImageCropAuto() {
// ImageCropAuto
if (!is_null($this->ica)) {
$this->DebugMessage('ImageCropAuto('.$this->ica.') starting', __FILE__, __LINE__);
if (function_exists('imagecropauto')) { // (PHP 5 >= 5.5.0, PHP 7)
// https://www.php.net/manual/en/function.imagecropauto.php
// 0 = IMG_CROP_DEFAULT
// 1 = IMG_CROP_TRANSPARENT
// 2 = IMG_CROP_BLACK
// 3 = IMG_CROP_WHITE
// 4 = IMG_CROP_SIDES
// 5 = IMG_CROP_THRESHOLD
if (preg_match('#^(([0-4])|(5)\\|(0?\\.?[0-9]+)\\|([0-9A-F]{6}))$#i', $this->ica, $matches)) {
@list($dummy, $dummy, $ica_mode1, $ica_mode2, $ica_threshold, $ica_color) = $matches;
if ($ica_mode2) {
$param_color = hexdec($ica_color);
if (!imageistruecolor($this->gdimg_source)) {
$param_color = imagecolorclosest($this->gdimg_source, hexdec(substr($ica_color, 0, 2)), hexdec(substr($ica_color, 2, 2)), hexdec(substr($ica_color, 4, 2)));
}
$cropped = imagecropauto($this->gdimg_source, intval($ica_mode2), floatval($ica_threshold), $param_color);
} else {
$cropped = imagecropauto($this->gdimg_source, intval($ica_mode1));
}
if ($cropped !== false) { // in case a new image resource was returned
$this->DebugMessage('ImageCropAuto changing source image size from '.imagesx($this->gdimg_source).'x'.imagesy($this->gdimg_source).' to '.imagesx($cropped).'x'.imagesy($cropped), __FILE__, __LINE__);
imagedestroy($this->gdimg_source); // we destroy the original image
$this->gdimg_source = $cropped; // and assign the cropped image to $im
$this->source_width = imagesx($this->gdimg_source);
$this->source_height = imagesy($this->gdimg_source);
} else {
$this->DebugMessage('imagecropauto failed', __FILE__, __LINE__);
}
} else {
$this->DebugMessage('invalid "ica" parameter syntax, ignoring', __FILE__, __LINE__);
}
} else {
$this->DebugMessage('!function_exists(imagecropauto), ignoring "ica" parameter', __FILE__, __LINE__);
}
}
return true;
}

public function phpThumbDebugVarDump($var) {
if (null === $var) {
Expand Down Expand Up @@ -4046,7 +4111,7 @@ public function phpThumbDebug($level='') {
}

$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');
$ParameterNames = array('src', 'new', 'w', 'h', 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'far', 'bg', 'bc', 'file', 'goto', 'err', 'xto', 'ra', 'ar', 'aoe', 'iar', 'maxb');
$ParameterNames = array('src', 'new', 'w', 'h', 'f', 'q', 'sx', 'sy', 'sw', 'sh', 'far', 'bg', 'bc', 'zc', 'ica', 'file', 'goto', 'err', 'xto', 'ra', 'ar', 'aoe', 'iar', 'maxb');
$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');
$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');

Expand Down

0 comments on commit dd37f90

Please sign in to comment.