title: How to crop image on upload with Rails, Carrierwave and Minimagick?
body: <p>I have read:</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/8418973/undefined-method-crop-using-carrierwave-with-minimagick-on-rails-3-1-3">Undefined Method crop! Using Carrierwave with MiniMagick on rails 3.1.3</a>   </li>
  <li><a href="https://stackoverflow.com/questions/6757359/carrierwave-cropping">Carrierwave Cropping</a></li>
  <li><a href="http://pastebin.com/ue4mVbC8" rel="nofollow noreferrer">http://pastebin.com/ue4mVbC8</a></li>
  </ul>
  
  <p>And so I tried:
  </p>
  
  <pre><code># encoding: utf-8
  
  class ProjectPictureUploader &lt; CarrierWave::Uploader::Base
    include CarrierWave::MiniMagick
  
    storage :file
    def store_dir
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
  
    version :thumb do
      process :cropper
      # process :crop
      process resize_to_fit: [200, 200]
    end
  
    def cropper
      manipulate! do |img| 
        # if model.crop_x.present?
          image = MiniMagick::Image.open(current_path)
          crop_w = (image[:width] * 0.8).to_i
          crop_y = (image[:height] * 0.8).to_i
          crop_x = (image[:width] * 0.1).to_i
          crop_y = (image[:height] * 0.1).to_i
        # end
        img = img.crop "#{crop_x}x#{crop_y}+#{crop_w}+#{crop_h}"
        img
      end 
    end
  
    def crop
      if model.crop_x.present?
        resize_to_limit(700, 700)
  
        manipulate! do |img|
          x = model.crop_x
          y = model.crop_y
          w = model.crop_w
          h = model.crop_h
  
          w &lt;&lt; 'x' &lt;&lt; h &lt;&lt; '+' &lt;&lt; x &lt;&lt; '+' &lt;&lt; y
  
          img.crop(w)
          img
        end
      end
    end
  
  end
  </code></pre>
  
  <p>Then I used <strong>cropper</strong>: undefined local variable or method `crop_h' for /uploads/tmp/20121006-2227-4220-9621/thumb_Koala.jpg:#</p>
  
  <p>Then <strong>crop</strong>: undefined method `crop_x' for #</p>
  
  <p>Model:</p>
  
  <pre><code>class Project &lt; ActiveRecord::Base
    ...
    mount_uploader :picture, ProjectPictureUploader
  end
  </code></pre>
  
  <p>Rails 3.2, Win7, </p>
  
  <p>convert -version
  Version: ImageMagick 6.7.9-4 2012-09-08 Q16 <a href="http://www.imagemagick.org" rel="nofollow noreferrer">http://www.imagemagick.org</a>
  Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
  Features: OpenMP</p>