From 9072ce59926c2c7d12131af229a60231df7b1d14 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 3 Apr 2024 19:51:41 +0200 Subject: [PATCH 1/4] post.php: strip metadata from png and webp image file types --- post.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/post.php b/post.php index 2cc99071..4781b87a 100644 --- a/post.php +++ b/post.php @@ -1113,7 +1113,8 @@ if (isset($_POST['delete'])) { $dont_copy_file = false; - if ($config['redraw_image'] || (!@$file['exif_stripped'] && $config['strip_exif'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg'))) { + $strippable_image_ext = $file['extension'] === 'jpg' || $file['extension'] === 'jpeg' || $file['extension'] === 'webp' || $file['extension'] == 'png'; + if ($config['redraw_image'] || (!@$file['exif_stripped'] && $config['strip_exif'] && $strippable_image_ext)) { if (!$config['redraw_image'] && $config['use_exiftool']) { try { $file['size'] = strip_image_metadata($file['tmp_name']); From 2bb1b0b9d4557e12ee0484d8fdb7f3c0177ce156 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 3 Apr 2024 21:24:10 +0200 Subject: [PATCH 2/4] post.php: remove double check --- post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post.php b/post.php index 4781b87a..bd7f798c 100644 --- a/post.php +++ b/post.php @@ -1052,7 +1052,7 @@ if (isset($_POST['delete'])) { if ($config['convert_auto_orient'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) { // The following code corrects the image orientation. // Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered. - if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool']) && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')))) { + if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool'])))) { if (in_array($config['thumb_method'], array('convert', 'convert+gifsicle', 'gm', 'gm+gifsicle'))) { $exif = @exif_read_data($file['tmp_name']); $gm = in_array($config['thumb_method'], array('gm', 'gm+gifsicle')); From 6ceee8261ef2802d5b0c50afe3b4b0a9760a25a8 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 3 Apr 2024 21:34:51 +0200 Subject: [PATCH 3/4] post.php: strip and reorient png and webp images --- post.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/post.php b/post.php index bd7f798c..05fb731e 100644 --- a/post.php +++ b/post.php @@ -1047,9 +1047,11 @@ if (isset($_POST['delete'])) { if ($size[0] > $config['max_width'] || $size[1] > $config['max_height']) { error($config['error']['maxsize']); } + // If, on the basis of the file extension, the image file has metadata we can operate on. + $file_image_has_operable_metadata = $file['extension'] === 'jpg' || $file['extension'] === 'jpeg' || $file['extension'] === 'webp' || $file['extension'] == 'png'; - if ($config['convert_auto_orient'] && ($file['extension'] == 'jpg' || $file['extension'] == 'jpeg')) { + if ($file_image_has_operable_metadata && $config['convert_auto_orient']) { // The following code corrects the image orientation. // Currently only works with the 'convert' option selected but it could easily be expanded to work with the rest if you can be bothered. if (!($config['redraw_image'] || (($config['strip_exif'] && !$config['use_exiftool'])))) { @@ -1113,8 +1115,7 @@ if (isset($_POST['delete'])) { $dont_copy_file = false; - $strippable_image_ext = $file['extension'] === 'jpg' || $file['extension'] === 'jpeg' || $file['extension'] === 'webp' || $file['extension'] == 'png'; - if ($config['redraw_image'] || (!@$file['exif_stripped'] && $config['strip_exif'] && $strippable_image_ext)) { + if ($config['redraw_image'] || ($file_image_has_operable_metadata && !@$file['exif_stripped'] && $config['strip_exif'])) { if (!$config['redraw_image'] && $config['use_exiftool']) { try { $file['size'] = strip_image_metadata($file['tmp_name']); From eaacf2719965cc4609778dfe0f5ddb2b24e7eaf7 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Wed, 3 Apr 2024 19:51:58 +0200 Subject: [PATCH 4/4] post.php: do not strip orientation metadata --- post.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post.php b/post.php index 05fb731e..c6575992 100644 --- a/post.php +++ b/post.php @@ -173,7 +173,7 @@ function ocr_image(array $config, string $img_path): string { * @throws RuntimeException Throws on IO errors. */ function strip_image_metadata(string $img_path): int { - $err = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= ' . escapeshellarg($img_path)); + $err = shell_exec_error('exiftool -overwrite_original -ignoreMinorErrors -q -q -all= -Orientation ' . escapeshellarg($img_path)); if ($err === false) { throw new RuntimeException('Could not strip EXIF metadata!'); }