You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
618 B

  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. Paperclip::Thumbnail.make(file, options, attachment)
  7. end
  8. private
  9. def needs_convert?
  10. needs_different_geometry? || needs_different_format?
  11. end
  12. def needs_different_geometry?
  13. !@target_geometry.nil? && @current_geometry.width != @target_geometry.width && @current_geometry.height != @target_geometry.height
  14. end
  15. def needs_different_format?
  16. @format.present? && @current_format != @format
  17. end
  18. end
  19. end