1
0
mirror of https://github.com/vichan-devel/vichan.git synced 2024-11-23 23:20:57 +01:00

Remove 'convert_manual_orient' functionality.

It was supposed to help in case the user had an unspecified imagemagik version that was old in 2013...
This commit is contained in:
Zankaria 2024-02-14 23:26:15 +01:00
parent e52c996a56
commit 24ebabb976
3 changed files with 7 additions and 103 deletions

View File

@ -788,8 +788,7 @@
// Strip EXIF metadata from JPEG files. // Strip EXIF metadata from JPEG files.
$config['strip_exif'] = false; $config['strip_exif'] = false;
// Use the command-line `exiftool` tool to strip EXIF metadata without decompressing/recompressing JPEGs. // 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 // Ignored when $config['redraw_image'] is true.
// $config['strip_exif'] is false and $config['convert_manual_orient'] is true.
$config['use_exiftool'] = false; $config['use_exiftool'] = false;
// Redraw the image to strip any excess data (commonly ZIP archives) WARNING: This might strip the // 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 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.) // this value doesn't matter as $config['redraw_image'] attempts to correct orientation too.)
$config['convert_auto_orient'] = false; $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. // 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 // Details: https://github.com/savetheinternet/Tinyboard/issues/20

View File

@ -324,12 +324,7 @@ class ImageConvert extends ImageBase {
error(_('Failed to resize image!'), null, $error); error(_('Failed to resize image!'), null, $error);
} }
} else { } else {
if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) $convert_args = &$config['convert_args'];
$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'];
if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' .
sprintf($convert_args, sprintf($convert_args,
@ -348,12 +343,8 @@ class ImageConvert extends ImageBase {
} }
} }
} else { } else {
if ($config['convert_manual_orient'] && ($this->format == 'jpg' || $this->format == 'jpeg')) $convert_args = &$config['convert_args'];
$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'];
if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' . if (($error = shell_exec_error(($this->gm ? 'gm ' : '') . 'convert ' .
sprintf($convert_args, sprintf($convert_args,
$this->width, $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 { class ImagePNG extends ImageBase {

View File

@ -999,27 +999,9 @@ if (isset($_POST['delete'])) {
$exif = @exif_read_data($file['tmp_name']); $exif = @exif_read_data($file['tmp_name']);
$gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle')); $gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle'));
if (isset($exif['Orientation']) && $exif['Orientation'] != 1) { if (isset($exif['Orientation']) && $exif['Orientation'] != 1) {
if ($config['convert_manual_orient']) { $error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' .
$error = shell_exec_error(($gm ? 'gm ' : '') . 'convert ' . escapeshellarg($file['tmp_name']) . ' -auto-orient ' . escapeshellarg($upload));
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));
}
if ($error) if ($error)
error(_('Could not auto-orient image!'), null, $error); error(_('Could not auto-orient image!'), null, $error);
$size = @getimagesize($file['tmp_name']); $size = @getimagesize($file['tmp_name']);