Class: Crimagify::ImageUploader
- Inherits:
-
CarrierWave::Uploader::Base
- Object
- CarrierWave::Uploader::Base
- Crimagify::ImageUploader
- Includes:
- CarrierWave::RMagick
- Defined in:
- app/uploaders/crimagify/image_uploader.rb
Class Method Summary collapse
-
.enable_processing(value = nil) ⇒ Object
ThisAreaIsForSizeVersions==========================================================.
Instance Method Summary collapse
- #crop ⇒ Object
-
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded.
-
#store_dir ⇒ Object
Override the directory where uploaded files will be stored.
Class Method Details
.enable_processing(value = nil) ⇒ Object
ThisAreaIsForSizeVersions==========================================================
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/uploaders/crimagify/image_uploader.rb', line 32 def self.enable_processing(value=nil) array_versions = [] CRIMAGIFY_ENV.each do |image_name| image_name[1].each do |name| name_version = name[1] name_version.each do |item| array_versions << item.first end end end return array_versions end |
Instance Method Details
#crop ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'app/uploaders/crimagify/image_uploader.rb', line 84 def crop width = 0 heigth = 0 parent = model.parent_type image_name = model.image_name if parent == "" aux_name = original_filename.split("-") parent = aux_name[3].to_s image_name = aux_name[4].to_s end CRIMAGIFY_ENV["#{parent}"]["#{image_name}"].each do |size_name| if size_name.first == "#{version_name}" if model.crop_x.present? manipulate! do |img| x = model.crop_x.to_i y = model.crop_y.to_i w = model.crop_w.to_i h = model.crop_h.to_i img.crop!(x, y, w, h) width = CRIMAGIFY_ENV["#{parent}"]["#{image_name}"]["#{version_name}"]['width'].to_i height = CRIMAGIFY_ENV["#{parent}"]["#{image_name}"]["#{version_name}"]['height'].to_i img.resize_to_fit(width, height) end end end end end |
#extension_white_list ⇒ Object
Add a white list of extensions which are allowed to be uploaded. For images you might use something like this:
80 81 82 |
# File 'app/uploaders/crimagify/image_uploader.rb', line 80 def extension_white_list %w(jpg jpeg gif png) end |
#store_dir ⇒ Object
Override the directory where uploaded files will be stored. This is a sensible default for uploaders that are meant to be mounted:
18 19 20 |
# File 'app/uploaders/crimagify/image_uploader.rb', line 18 def store_dir "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" end |