From e6ebc54b6cc5d08977b0686b8b776e2cb13d2a8f Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 31 Oct 2022 14:01:48 -0500 Subject: [PATCH] media assets: include image width, height, and file type in EXIF metadata. Previously the width, height, and file type fields returned by ExifTool weren't saved in the media metadata because they were already saved in the media asset. However, in some cases, it can be useful to compare ExifTool's version of these fields with our own. This can be useful when an image is corrupt and libvips can't get the width or height, or when it's a video and we want to make sure we detected the correct type of video. script/files/123_refresh_media_metatadata.rb needs to be run after this to update the metadata. --- app/logical/exif_tool.rb | 4 ++-- test/unit/media_file_test.rb | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/logical/exif_tool.rb b/app/logical/exif_tool.rb index 8a9b5c574..115aac03d 100644 --- a/app/logical/exif_tool.rb +++ b/app/logical/exif_tool.rb @@ -9,8 +9,8 @@ class ExifTool # @see https://exiftool.org/exiftool_pod.html#OPTIONS DEFAULT_OPTIONS = %q( -G1 -duplicates -unknown -struct --binary - -x 'System:*' -x ExifToolVersion -x FileType -x FileTypeExtension - -x MIMEType -x ImageWidth -x ImageHeight -x ImageSize -x MegaPixels + -x 'System:*' -x ExifToolVersion -x FileTypeExtension + -x MIMEType -x ImageSize -x MegaPixels ).squish attr_reader :file diff --git a/test/unit/media_file_test.rb b/test/unit/media_file_test.rb index 3e55381f4..fd0f9e324 100644 --- a/test/unit/media_file_test.rb +++ b/test/unit/media_file_test.rb @@ -273,7 +273,7 @@ class MediaFileTest < ActiveSupport::TestCase assert_equal(true, @metadata["Flash:Compressed"]) assert_not_equal("Install Compress::Zlib to extract compressed information", @metadata["ExifTool:Warning"]) - assert_equal(6, @metadata.count) + assert_equal(9, @metadata.count) end end @@ -469,7 +469,7 @@ class MediaFileTest < ActiveSupport::TestCase assert_equal(true, @file.is_corrupt?) assert_equal("File format error", @metadata["ExifTool:Error"]) assert_equal("89a", @metadata["GIF:GIFVersion"]) - assert_equal(6, @metadata.count) + assert_equal(9, @metadata.count) end should "not raise an exception when reading the frame count" do @@ -480,7 +480,7 @@ class MediaFileTest < ActiveSupport::TestCase assert_equal(nil, @file.frame_count) assert_equal("File format error", @metadata["ExifTool:Error"]) assert_equal("89a", @metadata["GIF:GIFVersion"]) - assert_equal(6, @metadata.count) + assert_equal(9, @metadata.count) assert_nothing_raised { @file.attributes } end end @@ -492,7 +492,7 @@ class MediaFileTest < ActiveSupport::TestCase assert_equal(true, @file.is_corrupt?) assert_equal("Grayscale", @metadata["PNG:ColorType"]) - assert_equal(6, @metadata.count) + assert_equal(9, @metadata.count) end end @@ -503,7 +503,7 @@ class MediaFileTest < ActiveSupport::TestCase assert_equal(true, @file.is_corrupt?) assert_equal(1, @metadata["File:ColorComponents"]) - assert_equal(7, @metadata.count) + assert_equal(10, @metadata.count) end end