diff options
author | imncls <himasoto@gmail.com> | 2018-02-23 23:28:31 +0900 |
---|---|---|
committer | imncls <himasoto@gmail.com> | 2018-02-23 23:28:31 +0900 |
commit | bb6988a7ac319c08776d8c07204232a67f992671 (patch) | |
tree | 4a53349374bc4a871a6ce74b786a8e747803155c /lib/paperclip/lazy_thumbnail.rb | |
parent | 544543e40a723d9719f5571bd4c3455a6a69fccd (diff) | |
parent | e668180044560e28bdc5eef94744c210013efcda (diff) |
Merge branch 'master' of https://github.com/tootsuite/mastodon
# Conflicts: # app/controllers/settings/exports_controller.rb # app/models/media_attachment.rb # app/models/status.rb # app/views/about/show.html.haml # docker_entrypoint.sh # spec/views/about/show.html.haml_spec.rb
Diffstat (limited to 'lib/paperclip/lazy_thumbnail.rb')
-rw-r--r-- | lib/paperclip/lazy_thumbnail.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/paperclip/lazy_thumbnail.rb b/lib/paperclip/lazy_thumbnail.rb new file mode 100644 index 000000000..42f9a557a --- /dev/null +++ b/lib/paperclip/lazy_thumbnail.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Paperclip + class LazyThumbnail < Paperclip::Thumbnail + def make + return File.open(@file.path) unless needs_convert? + Paperclip::Thumbnail.make(file, options, attachment) + end + + private + + def needs_convert? + needs_different_geometry? || needs_different_format? + end + + def needs_different_geometry? + !@target_geometry.nil? && @current_geometry.width != @target_geometry.width && @current_geometry.height != @target_geometry.height + end + + def needs_different_format? + @format.present? && @current_format != @format + end + end +end |