开发者

Rails 3: cropping the display of an image on the fly

I was wondering if anyone has ever made something that would let a user change the cropping of an image's display on the fly?

What I'm imagining is a user uploads a photo which does not get cropped and when the photo is displayed on their dashboard they can select a 'crop display' option and select a rectangul开发者_如何转开发ar area of the image to be displayed, however, the actual photo is not cropped, and a user could repeat this and display a different section of the same photo. Anyone ever done this or have idea on how it could be done? Thanks a bunch!


Dragonfly does this.

It's a Rack framework with on-the-fly image processing as one of its main points. Basic usage:

class Album < ActiveRecord::Base
  image_accessor :cover_image
end

<%= image_tag @album.cover_image.url %>
<%= image_tag @album.cover_image.thumb('400x200#').url %>
<%= image_tag @album.cover_image.jpg.url %>
<%= image_tag @album.cover_image.process(:greyscale).encode(:tiff).url %>

To make your example work, you could surely use any cropping tool and pass the arguments to the server to create multiple re-usable "crops", or other views (note the grayscale, etc).


You can use this jquery plugin as an interface http://code.google.com/p/jcrop/ and you should watch this railscast: http://railscasts.com/episodes/182-cropping-images to get know how it works "under the hood" :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜