Auto-add automatic tags whenever post is updated
Instead of being limited to when it's first uploaded.
This commit is contained in:
@@ -424,6 +424,7 @@ class Post < ActiveRecord::Base
|
||||
normalized_tags = TagAlias.to_aliased(normalized_tags)
|
||||
normalized_tags = TagImplication.with_descendants(normalized_tags)
|
||||
normalized_tags = %w(tagme) if normalized_tags.empty?
|
||||
normalized_tags = add_automatic_tags(normalized_tags)
|
||||
normalized_tags.sort!
|
||||
set_tag_string(normalized_tags.uniq.sort.join(" "))
|
||||
end
|
||||
@@ -434,6 +435,37 @@ class Post < ActiveRecord::Base
|
||||
return tags - negated_tags
|
||||
end
|
||||
|
||||
def add_automatic_tags(tags)
|
||||
return tags if !Danbooru.config.enable_dimension_autotagging
|
||||
|
||||
tags -= %w(incredibly_absurdres absurdres highres lowres huge_filesize)
|
||||
|
||||
if image_width >= 10_000 || image_height >= 10_000
|
||||
tags << "incredibly_absurdres"
|
||||
end
|
||||
if image_width >= 3200 || image_height >= 2400
|
||||
tags << "absurdres"
|
||||
end
|
||||
if image_width >= 1600 || image_height >= 1200
|
||||
tags << "highres"
|
||||
end
|
||||
if image_width <= 500 && image_height <= 500
|
||||
tags << "lowres"
|
||||
end
|
||||
|
||||
if file_size >= 10.megabytes
|
||||
tags << "huge_filesize"
|
||||
end
|
||||
|
||||
if image_width >= 1024 && image_width.to_f / image_height >= 4
|
||||
tags << "wide_image"
|
||||
elsif image_height >= 1024 && image_height.to_f / image_width >= 4
|
||||
tags << "tag_image"
|
||||
end
|
||||
|
||||
return tags
|
||||
end
|
||||
|
||||
def filter_metatags(tags)
|
||||
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent):/i}
|
||||
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|child):/i}
|
||||
|
||||
@@ -77,10 +77,8 @@ class Upload < ActiveRecord::Base
|
||||
validate_md5_uniqueness
|
||||
validate_md5_confirmation
|
||||
calculate_file_size(file_path)
|
||||
add_file_size_tags!(file_path)
|
||||
if has_dimensions?
|
||||
calculate_dimensions(file_path)
|
||||
add_dimension_tags!
|
||||
end
|
||||
generate_resizes(file_path)
|
||||
move_file
|
||||
@@ -174,31 +172,6 @@ class Upload < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def add_dimension_tags!
|
||||
return if !Danbooru.config.enable_dimension_autotagging
|
||||
|
||||
%w(incredibly_absurdres absurdres highres lowres).each do |tag|
|
||||
escaped_tag = Regexp.escape(tag)
|
||||
self.tag_string = tag_string.gsub(/(?:\A| )#{escaped_tag}(?:\Z| )/, " ").strip
|
||||
end
|
||||
|
||||
if image_width >= 10_000 || image_height >= 10_000
|
||||
self.tag_string = "#{tag_string} incredibly_absurdres".strip
|
||||
elsif image_width >= 3200 || image_height >= 2400
|
||||
self.tag_string = "#{tag_string} absurdres".strip
|
||||
elsif image_width >= 1600 || image_height >= 1200
|
||||
self.tag_string = "#{tag_string} highres".strip
|
||||
elsif image_width <= 500 && image_height <= 500
|
||||
self.tag_string = "#{tag_string} lowres".strip
|
||||
end
|
||||
|
||||
if image_width >= 1024 && image_width.to_f / image_height >= 4
|
||||
self.tag_string = "#{tag_string} wide_image".strip
|
||||
elsif image_height >= 1024 && image_height.to_f / image_width >= 4
|
||||
self.tag_string = "#{tag_string} tall_image".strip
|
||||
end
|
||||
end
|
||||
|
||||
# Does this file have image dimensions?
|
||||
def has_dimensions?
|
||||
%w(jpg gif png swf).include?(file_ext)
|
||||
@@ -406,12 +379,6 @@ class Upload < ActiveRecord::Base
|
||||
extend SearchMethods
|
||||
include ApiMethods
|
||||
|
||||
def add_file_size_tags!(file_path)
|
||||
if file_size >= 10.megabytes
|
||||
self.tag_string = "#{tag_string} huge_filesize".strip
|
||||
end
|
||||
end
|
||||
|
||||
def uploader_name
|
||||
User.id_to_name(uploader_id)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user