posts: automatically tag animated_gif & animated_png on tag edit.
Automatically tag animated_gif and animated_png when a post is edited. Add them back if the user tries to remove them from an animated post, or remove them if the user tries to add them to a non-animated post. Before we added these tags at upload time, but it was possible for users to remove them after upload, or to incorrectly add them to non-animated posts. They were added at upload time because we couldn't afford to open the file and parse the metadata on every tag edit. Now that we save the metadata in the database, we can do this. This also makes it so you can't tag ugoira on non-ugoira files. Known bug: it's possible to have an animated GIF where every frame is identical. Post #3770975 is an example. This will be detected as an animated GIF even though visually it doesn't appear to be animated. Fixes #4041: Animated_gif tag not added to preprocessed uploads
This commit is contained in:
@@ -69,8 +69,6 @@ class UploadService
|
||||
def automatic_tags(media_file)
|
||||
tags = []
|
||||
tags << "sound" if media_file.has_audio?
|
||||
tags << "animated_gif" if media_file.file_ext == :gif && media_file.is_animated?
|
||||
tags << "animated_png" if media_file.file_ext == :png && media_file.is_animated?
|
||||
tags.join(" ")
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class MediaAsset < ApplicationRecord
|
||||
has_one :media_metadata, dependent: :destroy
|
||||
delegate :metadata, to: :media_metadata
|
||||
|
||||
def self.search(params)
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :md5, :file_ext, :file_size, :image_width, :image_height)
|
||||
@@ -17,4 +18,16 @@ class MediaAsset < ApplicationRecord
|
||||
self.image_height = media_file.height
|
||||
self.media_metadata = MediaMetadata.new(file: media_file)
|
||||
end
|
||||
end
|
||||
|
||||
def is_animated?
|
||||
is_animated_gif? || is_animated_png?
|
||||
end
|
||||
|
||||
def is_animated_gif?
|
||||
file_ext == "gif" && metadata.fetch("GIF:FrameCount", 1) > 1
|
||||
end
|
||||
|
||||
def is_animated_png?
|
||||
file_ext == "png" && metadata.fetch("PNG:AnimationFrames", 1) > 1
|
||||
end
|
||||
end
|
||||
@@ -498,7 +498,7 @@ class Post < ApplicationRecord
|
||||
end
|
||||
|
||||
def add_automatic_tags(tags)
|
||||
tags -= %w[incredibly_absurdres absurdres highres lowres huge_filesize flash]
|
||||
tags -= %w[incredibly_absurdres absurdres highres lowres huge_filesize flash video ugoira animated_gif animated_png]
|
||||
|
||||
if image_width >= 10_000 || image_height >= 10_000
|
||||
tags << "incredibly_absurdres"
|
||||
@@ -537,13 +537,11 @@ class Post < ApplicationRecord
|
||||
tags << "ugoira"
|
||||
end
|
||||
|
||||
if !is_gif?
|
||||
tags -= ["animated_gif"]
|
||||
end
|
||||
|
||||
if !is_png?
|
||||
tags -= ["animated_png"]
|
||||
end
|
||||
# Allow only Flash files to be manually tagged as `animated`; GIFs, PNGs, videos, and ugoiras are automatically tagged.
|
||||
tags -= ["animated"] unless is_flash?
|
||||
tags << "animated" if media_asset.is_animated?
|
||||
tags << "animated_gif" if media_asset.is_animated_gif?
|
||||
tags << "animated_png" if media_asset.is_animated_png?
|
||||
|
||||
tags
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user