title: Rails 4, Carrierwave, Jcrop, image upload and resizing
body: <p><strong>UPDATE</strong>
  I moved the crop code from the uploader directly to the Notebook Model so that it gets called at least. Now, the image is getting processed. It's getting cropped in fact, to the correct width and height dimensions, but the x and y offsets are wrong. I'm using MiniMagick, not RMagick. Here is my crop_image method:</p>
  
  <pre class="lang-rb prettyprint-override"><code>def crop_image
      if crop_x.present?
          image.manipulate! do |img|
              x = crop_x.to_i
              y = crop_y.to_i
              w = crop_w.to_i
              h = crop_h.to_i
  
              z = "#{w}x#{h}+#{x}+#{y}"
              img.resize "600x600"
              img.crop(z)
              img
          end
      end
      image.resize_to_fill(224, 150)
  end
  </code></pre>
  
  <hr>
  
  <p>Has something changed in Rails 4 with regards to carrierwave or imagemagick? I copied over code that I had working (in a Rails 3 application) to upload an image, crop it, and save both versions, but I can't get it to work in the Rails 4 app.</p>
  
  <p>Here are the relevant parts:</p>
  
  <pre class="lang-rb prettyprint-override"><code>class Notebook &lt; ActiveRecord::Base
      validates :title, :access, presence: true
      mount_uploader  :image, ImageUploader
      belongs_to :user
      has_many :invites
      attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
      after_update    :crop_image
  
      def notebook_title
          title
      end
  
      def user_name
          user.name
      end
  
      def crop_image
          image.recreate_versions! if crop_x.present?
      end
  end
  </code></pre>
  
  <p>And the recreate_versions! call accesses the image_uploader</p>
  
  <pre class="lang-rb prettyprint-override"><code>class ImageUploader &lt; CarrierWave::Uploader::Base
  
    include CarrierWave::MiniMagick
  
    include Sprockets::Rails::Helper
  
    storage :file
  
    include CarrierWave::MimeTypes
    process :set_content_type
  
    def store_dir
      "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    end
  
    # Create different versions of your uploaded files:
    version :large do
      process resize_to_limit: [600, 600]
    end
  
    version :thumb do
      process :crop
      resize_to_fill(224, 150)
    end
  
    def err
      raise "error here"
    end
  
    def crop
      if model.crop_x.present?
        resize_to_limit(600, 600)
  
        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
  
          size = w &lt;&lt; 'x' &lt;&lt; h
          offset = '+' &lt;&lt; x &lt;&lt; '+' &lt;&lt; y
  
          img.crop("#{size}#{offset}") 
          img
        end
       end
    end
  end
  </code></pre>
  
  <p>I'm seeing values for crop_x, crop_y, crop_w, and crop_h. The version :thumb block does not seem to call any process methods. Even if I try to raise an error from inside the version :thumb block, it doesn't work.</p>
  
  <p>If anyone can provide any info that would be great.</p>