about summary refs log tree commit diff
path: root/lib/paperclip/lazy_thumbnail.rb
blob: 42f9a557ac7c567bd50807f75adfcaa575725090 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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