class Sunrise::CarrierWave::BaseUploader
Public Instance Methods
cropper(*geometry) { |img| ... }
click to toggle source
Crop image by specific coordinates www.imagemagick.org/script/command-line-processing.php?ImageMagick=6ddk6c680muj4eu2vr54vdveb7#geometry process :cropper => [size, offset] process :cropper => [800, 600, 10, 20]
# File lib/sunrise/carrierwave/base_uploader.rb, line 73 def cropper(*geometry) geometry = normalize_param(geometry[0]) if geometry.size == 1 if geometry && geometry.size == 4 manipulate! do |img| img.crop '%ix%i+%i+%i' % geometry img = yield(img) if block_given? img end end end
default_url()
click to toggle source
# File lib/sunrise/carrierwave/base_uploader.rb, line 85 def default_url image_name = [model.class.to_s.underscore, version_name].compact.join('_') "/assets/defaults/#{image_name}.png" end
dimensions()
click to toggle source
# File lib/sunrise/carrierwave/base_uploader.rb, line 95 def dimensions [magick[:width], magick[:height]] end
image?(new_file = nil)
click to toggle source
# File lib/sunrise/carrierwave/base_uploader.rb, line 90 def image?(new_file = nil) _type = (file || new_file).content_type _type.include?('image') && %w[photoshop psd].none? { |p| _type.include?(p) } end
magick()
click to toggle source
# File lib/sunrise/carrierwave/base_uploader.rb, line 99 def magick @magick ||= ::MiniMagick::Image.new(current_path) end
quality(percentage) { |img| ... }
click to toggle source
Reduces the quality of the image to the percentage given process :quality => 85
# File lib/sunrise/carrierwave/base_uploader.rb, line 41 def quality(percentage) percentage = normalize_param(percentage) if percentage.present? manipulate! do |img| img.quality(percentage.to_s) img = yield(img) if block_given? img end end end
rotate(degrees = nil) { |img| ... }
click to toggle source
Rotate image by degress process :rotate => “-90”
# File lib/sunrise/carrierwave/base_uploader.rb, line 56 def rotate(degrees = nil) degrees = normalize_param(degrees) if degrees.present? manipulate! do |img| img.rotate(degrees.to_s) img = yield(img) if block_given? img end end end
store_dir()
click to toggle source
default store assets path
# File lib/sunrise/carrierwave/base_uploader.rb, line 23 def store_dir "uploads/#{model.class.to_s.underscore}/#{model.id}" end
strip() { |img| ... }
click to toggle source
Strips out all embedded information from the image process :strip
# File lib/sunrise/carrierwave/base_uploader.rb, line 30 def strip manipulate! do |img| img.strip img = yield(img) if block_given? img end end
Protected Instance Methods
normalize_param(value)
click to toggle source
# File lib/sunrise/carrierwave/base_uploader.rb, line 114 def normalize_param(value) if value.is_a?(Proc) || value.is_a?(Method) evaluate_method(model, value, file) else value end end
set_dimensions()
click to toggle source
# File lib/sunrise/carrierwave/base_uploader.rb, line 110 def set_dimensions model.width, model.height = dimensions if image? && model.has_dimensions? end
set_model_info()
click to toggle source
# File lib/sunrise/carrierwave/base_uploader.rb, line 105 def set_model_info model.data_content_type = file.content_type model.data_file_size = file.size end