I am working on the ability to crop images using carrierwave and Jcrop. Its a combination of Railscasts episode 182 and 253. I have cropping working but it crops the original. Is there anyway to force manupulate!
to use a different version?
def crop_image(x,y,w,h)
manipulate! do |img|
img.crop(x.to_i, y.to_i, w.to_i, h.to_i)
end
end
or is there a way to set the version from the model call?
attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
attr_accessible :description, :image, :crop_x, :crop_y, :crop_w, :crop_h
after_update :reprocess_image, :if => :cropping?
def cropping?
!crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
end
def reprocess_image
image.crop_image(crop_x, crop_y, crop_w, crop_h)
end
If I correctly understand the problem more simple way is to send trueSize option to the Jcrop.
Ryan just updated railscasts #182, it uses CarrierWave now
http://railscasts.com/episodes/182-cropping-images-revised
In the railscast, Ryan's solution was to convert the coords to work with the original image by finding the ratio between the large version and the original version. I was able to get it to work with Carrierwave and jCrop by following the same logic. Interesting enough Carrierwave does not store the dimensions of the images. I was able to hack together something from this post: http://code.dblock.org/ShowPost.aspx?Id=194.
Here is my solution.
user.rb
account_controller.rb
profile_uploader.rb
crop.html.erb
style.css