logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

lazy_thumbnail.rb (822B)


  1. # frozen_string_literal: true
  2. module Paperclip
  3. class LazyThumbnail < Paperclip::Thumbnail
  4. def make
  5. return File.open(@file.path) unless needs_convert?
  6. min_side = [@current_geometry.width, @current_geometry.height].min
  7. options[:geometry] = "#{min_side.to_i}x#{min_side.to_i}#" if @target_geometry.square? && min_side < @target_geometry.width
  8. Paperclip::Thumbnail.make(file, options, attachment)
  9. end
  10. private
  11. def needs_convert?
  12. needs_different_geometry? || needs_different_format?
  13. end
  14. def needs_different_geometry?
  15. !@target_geometry.nil? && @current_geometry.width != @target_geometry.width && @current_geometry.height != @target_geometry.height
  16. end
  17. def needs_different_format?
  18. @format.present? && @current_format != @format
  19. end
  20. end
  21. end