开发者

zooming image in ruby

Can anyone tell me the way to zoom the image in Ruby 开发者_如何学编程on rails please ?


There's railscast #182 on image Cropping.

If you are using Paperclip, you may specify different sizes for thumbnails, like this:

class Client < ActiveRecord::Base

  LOGO_STYLES = {
    :original => ['1024x768>', :jpg],
    :big      => ['512x384#', :jpg],
    :medium   => ['256x192#', :jpg],
    :small    => ['128x96#', :jpg]
  }

  has_attached_file :logo, :styles => Client::LOGO_STYLES
  attr_protected :logo_file_name, :logo_content_type, :logo_size

Finally, if you already have the image with the size you want, and you only want to change how it looks on the client, then your problem isn't ruby - it is javascript. Google for "javascript zoom" instead of "rails zoom" :)


You should be clearer.

If what you want to do is allow the user to zoom on an image then you should take a look at javascript.
For example jqzoom, which does a zoom on an image when your mouse is on it.

If what you want is to resize the image to a specific size then it's a ruby/rails problem.
And you can use paperclip to do so.

In your model, you'd add the following :

has_attached_file :my_image, :styles => { :thumb => ["32x32#", :png] }

Where the "32x32" will be the size of the image after it's been resized.

Then you follow the paperclip's README to see the migration and informations to add to the view.
And when you'll validate your form, the image will be automatically uploaded and resized.

If you don't wish to upload the files before to resize them, you can use Paperclip::Thumbnail directly.

And resize your image with the following :

Paperclip::Thumbnail.new('/path/to/your/file', { :geometry => '32x32#' }).make

And you'll have your thumbnail.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜