Class: ActiveStorage::Blurhash::Thumbnail::Vips

Inherits:
Object
  • Object
show all
Defined in:
lib/active_storage/blurhash/thumbnail/vips.rb

Instance Method Summary collapse

Constructor Details

#initialize(image) ⇒ Vips

Returns a new instance of Vips.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_storage/blurhash/thumbnail/vips.rb', line 7

def initialize(image)
  @thumbnail = ::Vips::Image.new_from_file(
    ::ImageProcessing::Vips.source(image.filename).resize_to_limit(200, 200).call.path
  )

  @thumbnail = case @thumbnail.bands
  when 1
    @thumbnail.bandjoin(Array.new(3 - @thumbnail.bands, @thumbnail))
  when 2
    @thumbnail.bandjoin(@thumbnail.extract_band(0))
  when 3
    @thumbnail
  else
    @thumbnail&.extract_band(0, n: 3)
  end
end

Instance Method Details

#pixelsObject



24
25
26
# File 'lib/active_storage/blurhash/thumbnail/vips.rb', line 24

def pixels
  @thumbnail&.to_a&.flatten || []
end