module RetinaRails::Processors::CarrierWave

Public Instance Methods

retina_quality(percentage) { |img| ... } click to toggle source

Process retina quality of the image. Works with ImageMagick and MiniMagick

Parameters

percentage (Int)

quality in percentage

# File lib/retina_rails/processors/carrierwave.rb, line 35
def retina_quality(percentage)
  manipulate! do |img|
    if defined?(Magick)
      img.write(current_path) { self.quality = percentage } unless img.quality == percentage
    elsif defined?(MiniMagick)
      img.quality(percentage.to_s)
    end
    img = yield(img) if block_given?
    img
  end
end
store_retina_dimensions() click to toggle source

Stores the original dimensions of the image as a serialized Hash in to the model

# File lib/retina_rails/processors/carrierwave.rb, line 10
def store_retina_dimensions
  if model
    width, height = `identify -format "%wx%h" '#{file.path}'`.split(/x/) ## Read dimensions

    ## Set original height and width attributes on model

    model.retina_dimensions = (model.retina_dimensions || {}).deep_merge!(
      mounted_as => {
        version_name => {
          :width  => width.to_i  / 2,
          :height => height.to_i / 2
        }
      }
    )
  end
end