How do you crop the image after the carrier wave "after the fact" in the rails?

What I would like to do is upload the image, and then transfer the user to a new page, where I will use Jcrop so that the user can select the part of the image that they want to crop, and then save this image. Essentially, I want to make this a two-step process.

I know how to make part of javascript, and I understand the main thread of how to create this functionality. However, I do not know the features of the carrier on how to do this .

The closest thing I can find is:

image.recreate_versions! 

But I still can't go height / width and start x, y to crop it.

For example, how can I say that the carrier wave performs cropping "after the fact" - that is, not when the image is loaded for the first time? I see methods for "processing" the image, but they happen automatically with a fixed height and width. How can i put this off?

Essentially, what I would like to do is dynamically determine the version where I can specify the height and width and x, y

thanks

+7
source share
1 answer

This is the best I can do. There is probably an easier way to do this, but this is my hack:

Here is my POST controller action when transmitting crop information:

  def update_crop @user = User.find(current_user.id) @user.crop(params[:x].to_i, params[:y].to_i, params[:h].to_i, params[:w].to_i) redirect_to(profile_path, :notice => 'Your profile and avatar was successfully updated.') end 

Here's a way to add a user that contains an avatar image downloader to the model:

  def crop(x, y, h, w) image = Magick::ImageList.new(avatar.current_path) cropped_image = image.crop(x, y, h, w) cropped_image.write(avatar.current_path) avatar.recreate_versions! end 

It basically just greets the current one, overwrites it, and then tells Carrierwave to create

+5
source

All Articles