media assets: fix dimensions of flash files.

Use ExifTool to get the dimensions of Flash files instead of calculating
it ourselves. Avoids copying third-party code.

Fixes a bug where Flash files with fractional dimensions (e.g. 607.6 x 756.6)
had their dimensions rounded down instead of rounded up.

Fixes another bug where Flash files could return negative dimensions.
This happened for two files:

* https://danbooru.donmai.us/media_assets/228662 (-179.2 x -339.2)
* https://danbooru.donmai.us/media_assets/228664 (-179.2 x -339.2)

Now we round these up to 1x1. This is still wrong, but it's less wrong than before.
This commit is contained in:
evazion
2022-10-31 17:12:52 -05:00
parent 2f2c73eebb
commit acc511ab7d
3 changed files with 9 additions and 88 deletions

View File

@@ -2,6 +2,7 @@
require_relative "base"
CurrentUser.user = User.system
condition = ENV.fetch("COND", "TRUE")
fix = ENV.fetch("FIX", "false").truthy?
@@ -17,6 +18,7 @@ MediaAsset.active.where(condition).find_each do |asset|
# Setting `file` updates the metadata if it's different.
asset.file = media_file
asset.media_metadata.file = media_file
asset.post.assign_attributes(image_width: asset.image_width, image_height: asset.image_height, file_ext: asset.file_ext, file_size: asset.file_size) if asset.post.present?
old = asset.media_metadata.metadata_was.to_h
new = asset.media_metadata.metadata.to_h
@@ -24,6 +26,7 @@ MediaAsset.active.where(condition).find_each do |asset|
puts ({ id: asset.id, **asset.changes, **metadata_changes }).to_json
if fix
asset.post.save! if asset.post&.changed?
asset.save! if asset.changed?
asset.media_metadata.save! if asset.media_metadata.changed?
end