Module: NextGenImages::CarrierwaveHelpers

Defined in:
lib/next_gen_images/carrierwave_helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_webp_full_filename(filename, version_name) ⇒ Object



19
20
21
22
23
# File 'lib/next_gen_images/carrierwave_helpers.rb', line 19

def build_webp_full_filename(filename, version_name)
  return "#{version_name}_#{filename}" if filename.split('.').last == 'webp'

  "#{version_name}_#{filename}.webp"
end

#convert_to_webp(options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/next_gen_images/carrierwave_helpers.rb', line 5

def convert_to_webp(options = {})
  webp_path = "#{path}.webp"

  WebP.encode(path, webp_path, options)

  @filename = webp_path.split('/').pop

  @file = CarrierWave::SanitizedFile.new(
    tempfile: webp_path,
    filename: webp_path,
    content_type: 'image/webp'
  )
end