acts_as_image
文件大小: unknow
源码售价: 5 个金币 积分规则     积分充值
资源说明:ActsAsImage Rails plugin
= ActsAsImage

This plugin takes a simple approach to saving images. It will scale images
and save them to the file system, but it can't be used to save other types of
files. It can handle all the types of images that RMagick can, and will
differentiate between normal images and animations, saving them as JPEG
and GIF respectively. You can specify as many different sizes as you
want and whether they will be scaled or cropped.

== Installing

Check out the plugin from the repository and put it into the vendor/plugins
directory:

  script/plugin install http://svn.2750flesk.com/plugins/trunk/acts_as_image

Use -x if you want Subversion to add an svn:externals entry
for the plugin.

== Model

If you haven't created your model yet, you can use the generator to create a model
and a migration that can be used with ActsAsImage:

  script/generate acts_as_image model Image

Then, migrate to create the new table:

  rake db:migrate

If you have an existing model that you want to use,
make sure it has the fields content_type, hash_string and original_filename.
In addition, the plugin will create an attribute file on the model that will be used to hold
the image before it is written to disk. Finally, add acts_as_image to the model class definition.

== Controller and view

You will have to add the uploaded file to the model's file attribute before
saving it. You can have this done automatically by making sure file is accessible
to mass assignment and naming the field in the form model_name[file].

== Paths and sizes

You can control which path the images will be written to, and what sizes the image will be resized to.
Here's an example model definition:

  class Image < ActiveRecord::Base
  
    acts_as_image #Must come first
    
    self.image_sizes = {
      :original => '100%x100%',
      :large => '>800x600',
      :medium => '>640x480',
      :small => '>320x200',
      :thumb => ['100x100!', :crop]
    }
    
    self.image_save_path = File.join(RAILS_ROOT, 'public', 'images', 'uploads')
    self.image_read_path = ['images', 'uploads'].join('/')
  
  end

Image.image_sizes contains a hash with the names and sizes of the images that will
be written to disk. The key will be used as the filename, and the value is an RMagick geometry
string (http://www.simplesystems.org/RMagick/doc/imusage.html#geometry). If the value is an
array, the first element is the geometry string and the second is either :crop or :scale, specifying
if the image should be scaled or cropped (after being resized). The original image won't be saved
by default, but you can specify an :original entry with '100%x100%' to achieve the
same result.

Image.image_save_path is the path in which the images will be written on the server.
Image.image_read_path is the path to the image that a browser sees.

Each image also has its own sub-path that consists of a MD5 hash that is split up into three parts.
This is to avoid hitting file system limits on how many files a directory can contain. So, the full
path to an image will look something like
public/images/uploads/3/d/35830c5caa0009b1e9b7d51964d280/small.jpg. The path for use in a view
can be retrieved via the url method on the image:

  <%= image_tag(image.url('small'), :alt => h(image.title)) %>

== Contact me

You can reach me by e-mail at toredarell a gmail , com

I will most likely not add new features, but bug fixes
(or just letting me know about them) or minor improvements are welcome.

本源码包内暂不包含可直接显示的源代码文件,请下载源码包。