Tuesday, 11 January 2022

Completed conditional versioning in carrierwave based on extension(image or video) with thumbinal

Add gem: 

gem 'mini_magick'

-----------------------------------------------------------------------

Added on uploader file: 


include CarrierWave::MiniMagick


version :thumb, :if => :is_image?  do

    process resize_to_fit: [450, 400]

  end


protected

  def is_image?(resource_file)

    content_type = resource_file.content_type

    extentions = %w(image/jpeg image/png image/jpg image/gif)

    extentions.include? content_type

  end 

No comments:

Post a Comment