From 90f12f2e5a41115a9a756f9dd38054736080d4f9 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Thu, 22 Feb 2018 00:35:46 +0100 Subject: Focal points (#6520) * Add focus param to media API, center thumbnails on focus point * Add UI for setting a focal point * Improve focal point icon on upload item * Use focal point in upload preview * Add focalPoint property to ActivityPub * Don't show focal point button for non-image attachments --- app/models/media_attachment.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/media_attachment.rb b/app/models/media_attachment.rb index 38f88e9f7..a4d9cd9d1 100644 --- a/app/models/media_attachment.rb +++ b/app/models/media_attachment.rb @@ -91,6 +91,24 @@ class MediaAttachment < ApplicationRecord shortcode end + def focus=(point) + return if point.blank? + + x, y = (point.is_a?(Enumerable) ? point : point.split(',')).map(&:to_f) + + meta = file.instance_read(:meta) || {} + meta['focus'] = { 'x' => x, 'y' => y } + + file.instance_write(:meta, meta) + end + + def focus + x = file.meta['focus']['x'] + y = file.meta['focus']['y'] + + "#{x},#{y}" + end + before_create :prepare_description, unless: :local? before_create :set_shortcode before_post_process :set_type_and_extension @@ -168,7 +186,7 @@ class MediaAttachment < ApplicationRecord end def populate_meta - meta = {} + meta = file.instance_read(:meta) || {} file.queued_for_write.each do |style, file| meta[style] = style == :small || image? ? image_geometry(file) : video_metadata(file) -- cgit