From 24ebabb9765b5fc0e7268110851333ec6fc36756 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 14 Feb 2024 23:26:15 +0100 Subject: [PATCH] Remove 'convert_manual_orient' functionality. It was supposed to help in case the user had an unspecified imagemagik version that was old in 2013... --- inc/config.php | 8 +----- inc/image.php | 78 ++------------------------------------------------ post.php | 24 ++-------------- 3 files changed, 7 insertions(+), 103 deletions(-) diff --git a/inc/config.php b/inc/config.php index 0e255118..972487c0 100644 --- a/inc/config.php +++ b/inc/config.php @@ -788,8 +788,7 @@ // Strip EXIF metadata from JPEG files. $config['strip_exif'] = false; // Use the command-line `exiftool` tool to strip EXIF metadata without decompressing/recompressing JPEGs. - // Ignored when $config['redraw_image'] is true. This is also used to adjust the Orientation tag when - // $config['strip_exif'] is false and $config['convert_manual_orient'] is true. + // Ignored when $config['redraw_image'] is true. $config['use_exiftool'] = false; // Redraw the image to strip any excess data (commonly ZIP archives) WARNING: This might strip the @@ -802,11 +801,6 @@ // this basically does the same thing as $config['redraw_image']. (If $config['redraw_image'] is enabled, // this value doesn't matter as $config['redraw_image'] attempts to correct orientation too.) $config['convert_auto_orient'] = false; - - // Is your version of ImageMagick or GraphicsMagick old? Older versions may not include the -auto-orient - // switch. This is a manual replacement for that switch. This is independent from the above switch; - // -auto-orrient is applied when thumbnailing too. - $config['convert_manual_orient'] = false; // Regular expression to check for an XSS exploit with IE 6 and 7. To disable, set to false. // Details: https://github.com/savetheinternet/Tinyboard/issues/20 diff --git a/inc/image.php b/inc/image.php index 5f7fc8a5..2429f682 100644 --- a/inc/image.php +++ b/inc/image.php @@ -324,12 +324,7 @@ class ImageConvert extends ImageBase { error(_('Failed to resize image!'), null, $error); } } else { - if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) - $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']); - elseif ($config['convert_manual_orient']) - $convert_args = str_replace('-auto-orient', '', $config['convert_args']); - else - $convert_args = &$config['convert_args']; + $convert_args = &$config['convert_args']; if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, @@ -348,12 +343,8 @@ class ImageConvert extends ImageBase { } } } else { - if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) - $convert_args = str_replace('-auto-orient', ImageConvert::jpeg_exif_orientation($this->src), $config['convert_args']); - elseif ($config['convert_manual_orient']) - $convert_args = str_replace('-auto-orient', '', $config['convert_args']); - else - $convert_args = &$config['convert_args']; + $convert_args = &$config['convert_args']; + if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . sprintf($convert_args, $this->width, @@ -380,69 +371,6 @@ class ImageConvert extends ImageBase { } } } - - // For when -auto-orient doesn't exist (older versions) - static public function jpeg_exif_orientation($src, $exif = false) { - if (!$exif) { - $exif = @exif_read_data($src); - if (!isset($exif['Orientation'])) - return false; - } - switch($exif['Orientation']) { - case 1: - // Normal - return false; - case 2: - // 888888 - // 88 - // 8888 - // 88 - // 88 - - return '-flop'; - case 3: - - // 88 - // 88 - // 8888 - // 88 - // 888888 - - return '-flip -flop'; - case 4: - // 88 - // 88 - // 8888 - // 88 - // 888888 - - return '-flip'; - case 5: - // 8888888888 - // 88 88 - // 88 - - return '-rotate 90 -flop'; - case 6: - // 88 - // 88 88 - // 8888888888 - - return '-rotate 90'; - case 7: - // 88 - // 88 88 - // 8888888888 - - return '-rotate "-90" -flop'; - case 8: - // 8888888888 - // 88 88 - // 88 - - return '-rotate "-90"'; - } - } } class ImagePNG extends ImageBase { diff --git a/post.php b/post.php index 248b372c..1aa1edf9 100644 --- a/post.php +++ b/post.php @@ -999,27 +999,9 @@ if (isset($_POST['delete'])) { $exif = @exif_read_data($file['tmp_name']); $gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle')); if (isset($exif['Orientation']) && $exif['Orientation'] != 1) { - if ($config['convert_manual_orient']) { - $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . - escapeshellarg($file['tmp_name']) . ' ' . - ImageConvert::jpeg_exif_orientation(false, $exif) . ' ' . - ($config['strip_exif'] ? '+profile "*"' : - ($config['use_exiftool'] ? '' : '+profile "*"') - ) . ' ' . - escapeshellarg($file['tmp_name'])); - if ($config['use_exiftool'] && !$config['strip_exif']) { - if ($exiftool_error = shell_exec_error( - 'exiftool -overwrite_original -q -q -orientation=1 -n ' . - escapeshellarg($file['tmp_name']))) - error(_('exiftool failed!'), null, $exiftool_error); - } else { - // TODO: Find another way to remove the Orientation tag from the EXIF profile - // without needing `exiftool`. - } - } else { - $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . - escapeshellarg($file['tmp_name']) . ' -auto-orient ' . escapeshellarg($upload)); - } + $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . + escapeshellarg($file['tmp_name']) . ' -auto-orient ' . escapeshellarg($upload)); + if ($error) error(_('Could not auto-orient image!'), null, $error); $size = @getimagesize($file['tmp_name']);