post replacement: rescale notes.

This commit is contained in:
evazion
2017-05-17 00:14:20 -05:00
parent 302bc52bf8
commit 9f1096e67f
3 changed files with 39 additions and 5 deletions

View File

@@ -127,6 +127,14 @@ class Note < ActiveRecord::Base
User.id_to_name(creator_id)
end
def rescale!(x_scale, y_scale)
self.x *= x_scale
self.y *= y_scale
self.width *= x_scale
self.height *= y_scale
save!
end
def update_post
if self.changed?
if Note.where(:is_active => true, :post_id => post_id).exists?

View File

@@ -17,11 +17,6 @@ class PostReplacement < ActiveRecord::Base
end
def process!
# TODO for posts with notes we need to rescale the notes if the dimensions change.
if post.notes.any?
raise NotImplementedError.new("Replacing images with notes not yet supported.")
end
# TODO for ugoiras we need to replace the frame data.
if post.is_ugoira?
raise NotImplementedError.new("Replacing ugoira images not yet supported.")
@@ -49,6 +44,7 @@ class PostReplacement < ActiveRecord::Base
post.file_size = upload.file_size
post.source = upload.source
post.tag_string = upload.tag_string
rescale_notes
post.comments.create!({creator: User.system, body: comment_replacement_message, do_not_bump_post: true}, without_protection: true)
ModAction.log(modaction_replacement_message)
@@ -62,6 +58,15 @@ class PostReplacement < ActiveRecord::Base
post.update_iqdb_async
end
def rescale_notes
x_scale = post.image_width.to_f / post.image_width_was.to_f
y_scale = post.image_height.to_f / post.image_height_was.to_f
post.notes.each do |note|
note.rescale!(x_scale, y_scale)
end
end
module SearchMethods
def search(params = {})
q = all