From a55885de87a649d4107d133064dcd64d8db72f83 Mon Sep 17 00:00:00 2001 From: Ollama Date: Thu, 12 Mar 2026 19:19:22 +0000 Subject: [PATCH] Fix technical issues from PR review Image_lib.php fixes: - Remove incorrect 'GPS' => PelTag::GPS_OFFSET mapping (GPS handled separately) - Fix PNG transparency: change imagealphablending to false - Add animated GIF detection: skip processing for animations - Add logging in stripExifFallback to show which APP markers are removed Migration optimization: - Use get()->getRow() instead of countAllResults() for lighter query - More efficient existence check before insert All changes address CodeRabbit technical review comments while maintaining the simplified multiselect-only UI (no toggle needed). --- ...06120000_MigrationEXIFStrippingOptions.php | 7 ++++--- app/Libraries/Image_lib.php | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/app/Database/Migrations/20260306120000_MigrationEXIFStrippingOptions.php b/app/Database/Migrations/20260306120000_MigrationEXIFStrippingOptions.php index 0ebfbfcde..ddd50466c 100644 --- a/app/Database/Migrations/20260306120000_MigrationEXIFStrippingOptions.php +++ b/app/Database/Migrations/20260306120000_MigrationEXIFStrippingOptions.php @@ -24,11 +24,12 @@ class MigrationEXIFStrippingOptions extends Migration ]; foreach ($configs as $config) { - $exists = $db->table('app_config') + $existing = $db->table('app_config') ->where('key', $config['key']) - ->countAllResults(); + ->get() + ->getRow(); - if ($exists == 0) { + if ($existing === null) { $db->table('app_config')->insert($config); } } diff --git a/app/Libraries/Image_lib.php b/app/Libraries/Image_lib.php index f03884c42..12c40b926 100644 --- a/app/Libraries/Image_lib.php +++ b/app/Libraries/Image_lib.php @@ -15,7 +15,6 @@ class Image_lib 'Copyright' => PelTag::COPYRIGHT, 'Software' => PelTag::SOFTWARE, 'DateTime' => PelTag::DATE_TIME, - 'GPS' => PelTag::GPS_OFFSET, ]; public function stripEXIF(string $filepath, array $fields_to_keep = []): bool @@ -112,7 +111,7 @@ class Image_lib return false; } - imagealphablending($image, true); + imagealphablending($image, false); imagesavealpha($image, true); $result = imagepng($image, $filepath, 9); @@ -123,6 +122,15 @@ class Image_lib private function stripExifGif(string $filepath): bool { + $content = file_get_contents($filepath); + if ($content === false) { + return false; + } + + if (strpos($content, "\x21\xF9\x04") !== false || strpos($content, 'NETSCAPE2.0') !== false) { + return true; + } + $image = @imagecreatefromgif($filepath); if ($image === false) { return false; @@ -195,6 +203,13 @@ class Image_lib return true; } + $marker_names = []; + foreach ($markers as $marker_info) { + $marker_byte = ord($content[$marker_info[0] + 1]); + $marker_names[] = 'APP' . ($marker_byte - 0xE0); + } + log_message('warning', "stripExifFallback: Removing all APP markers from {$filepath}: " . implode(', ', $marker_names)); + $new_content = $content; foreach (array_reverse($markers) as $marker_info) { $new_content = substr_replace($new_content, '', $marker_info[0], $marker_info[1]);