Change timing to get image size
This commit is contained in:
parent
2eae1bb9bf
commit
2cdaf2af76
2 changed files with 13 additions and 6 deletions
|
@ -1,7 +1,5 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'fastimage'
|
||||
|
||||
module Admin
|
||||
class CustomEmojisController < BaseController
|
||||
def index
|
||||
|
@ -20,11 +18,7 @@ module Admin
|
|||
def create
|
||||
authorize :custom_emoji, :create?
|
||||
|
||||
image_size = FastImage.size(params[:custom_emoji][:image])
|
||||
|
||||
@custom_emoji = CustomEmoji.new(resource_params)
|
||||
@custom_emoji.image_width = image_size[0]
|
||||
@custom_emoji.image_height = image_size[1]
|
||||
|
||||
if @custom_emoji.save
|
||||
log_action :create, @custom_emoji
|
||||
|
|
|
@ -56,6 +56,8 @@ class CustomEmoji < ApplicationRecord
|
|||
|
||||
after_commit :remove_entity_cache
|
||||
|
||||
after_post_process :set_size
|
||||
|
||||
def local?
|
||||
domain.nil?
|
||||
end
|
||||
|
@ -99,4 +101,15 @@ class CustomEmoji < ApplicationRecord
|
|||
def downcase_domain
|
||||
self.domain = domain.downcase unless domain.nil?
|
||||
end
|
||||
|
||||
def set_size
|
||||
image.queued_for_write.each do |style, file|
|
||||
if style == :original
|
||||
image_size = FastImage.size(file.path)
|
||||
self.image_width = image_size[0]
|
||||
self.image_height = image_size[1]
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue