DynamicImage is a rails engine providing transparent uploading, resizing and processing on the fly, and caching of image files.
Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
db/migrate
lib
tasks
test
MIT-LICENSE
README.rdoc
Rakefile
TODO
about.yml
init.rb
install.rb
routes.rb
uninstall.rb

README.rdoc

Note:

This plugin used to be called dynamic_image, but has been superseded by a new plugin without the Engines dependency. The new plugin is here: github.com/elektronaut/dynamic_image

DynamicImage

DynamicImage is a rails engine providing transparent uploading, resizing and processing on the fly, and caching of image files.

Requirements:

DynamicImage is targetting both Rails 1.2.x and 2.x, and should be compatible with both. Earlier versions might work, but haven't been tested.

Database notice:

DynamicImage uses two tables, images and binaries. Please make sure these don't clash with your current database schema. If they do, you need to do your own migrations.

Installation:

You can install the plugin from github:

script/plugin install git://github.com/elektronaut/dynamic_image_engine.git

Once the plugin is installed, you need to create the database tables:

script/generate plugin_migration dynamic_image
rake db:migrate

The routes also need to be hooked up, add the following line somewhere in your config/routes.rb file:

map.from_plugin :dynamic_image

Usage:

Uploading an image

Creating a new image from an uploaded file is simple, here's some example view code:

<% form_for 'image', Image.new, :html => {:multipart => true} do |f| %>
  Name: <%= f.text_field :name %>
  File: <%= f.file_field :imagefile %>
  <%= submit_tag "Upload" %>
<% end %>

And for the controller:

@image = Image.create(params[:image])

Displaying an image

Use the dynamic_image_tag helper in your views to display an image, for example:

<%= dynamic_image_tag @user.avatar, :size => '64x64' %>
<%= dynamic_image_tag @user.avatar, :size => '150x', :filterset => 'dropshadow' %>

See ApplicationHelper.dynamic_image_tag for more info.

Associations

Using the belongs_to_image macro enables you to set an image directly from an uploaded file. Example:

class User
  belongs_to_image :avatar
end

Refer to ActiveRecord::Associations::ClassMethods for documentation.

Filtersets

Filtersets provide an easy way to process your thumbnails through ImageMagick. You can create multiple filtersets, and use them in a dynamic_image_tag with the :filterset option. They are documented in DynamicImage::Filterset.

Caching:

Processing images on the fly is expensive. Therefore, page caching is enabled by default, even in development mode. To disable page caching, add the following line in your initializers or environment.rb:

DynamicImage.page_caching = false