Hey all, I'm currently trying to code a custom image cropping system similar to other ones on the internet where a user can select a cropping area and then have their image cropped accordingly. The application is in Rails and we're using Paperclip with Amazon S3 to store the files. I'm having a lot of trouble though getting RMagick to appropriately crop the file from S3. Here is the current code (which does not work):
if params[:width].to_i > 0 and params[:height].to_i > 0 then
photo = Photo.find(params[:id])
image_data = Net::HTTP.get_response(URI.parse(photo.photo.url(:big))).body
orig_img = Magick::ImageList.new
orig_img.from_blob(image_data)
args = [params[:x1].to_i, params[:y1].to_i, params[:width].to_i, params[:height].to_i]
orig_img.crop!(*args)
photo.update_attributes({:photo => orig_img.to_blob})
photo.photo.reprocess!
photo.save
end
The main problem is that the cropped image is not uploaded back to S3 through paperclip, and thus not properly cropped. Has anyone attempted something like this with paperclip before? This may not even possible, but any help would be greatly appreciated.