0
@@ -2,6 +2,75 @@ require 'has_image/processor'
0
require 'has_image/storage'
0
require 'has_image/view_helpers'
0
+# HasImage allows you to very easily attach images to a Rails model. For some
0
+# more basic info on what it does, please see its {project
0
+# page}[http://github.com/norman/has_image] on GitHub.
0
+# Install HasImage by using Ruby Gems:
0
+# sudo gem install has_image
0
+# To use HasImage in your project, you must add a varchar column to your
0
+# model. By default, this column should be named "has_image_file," though you
0
+# may easily change this. For option defaults, see
0
+# HasImage#default_options_for and ClassMethods#has_image.
0
+# Uses all default options. This works, but is likely not what you need.
0
+# class Photo < ActiveRecord::Base
0
+# Resize the uploaded image to 800x800 and create a 150x150 thumbnail.
0
+# has_image :resize_to "800x800", :thumbnails => {:square => "150x150"}
0
+# Resize the image and set a max file size to 4 megabytes.
0
+# has_image :resize_to "100x150", :max_size => 4.megabytes
0
+# == Some slightly more advanced examples
0
+# === Localizing HasImage
0
+# has_image :invalid_image_message => "No se puede procesar la imagen."
0
+# === Using has_image with Capistrano
0
+# When deploying using Capistrano, you will likely want to keep images
0
+# under a "system" directory so that newly deployed versions have access
0
+# has_image :resize_to => "150x150",
0
+# :base_path => File.join(Rails.root, 'public', 'system')
0
+# === Testing with HasImage:
0
+# If you want your tests to actually run the image processing, you should
0
+# make sure your tests write the image files somewhere outside your public
0
+# directory. Add something like this to your config/environments/test.rb:
0
+# config.after_initialize do
0
+# MyClass.has_image_options[:base_path] = File.join(RAILS_ROOT, "tmp")
0
+# If you want to stub out calls to has_image so that your tests don't do
0
+# the (slow) image processing, here's an example using Test::Unit and
0
+# Photo.any_instance.stubs(:image_data=).returns(true)
0
+# Photo.any_instance.stubs(:install_images).returns(true)
0
+# Photo.any_instance.stubs(:image_data_valid?).returns(true)
0
class ProcessorError < StandardError ; end
0
@@ -72,14 +141,7 @@ module HasImage
0
- # To use HasImage with a Rails model, all you have to do is add a column
0
- # named "has_image_file." For configuration defaults, you might want to
0
- # take a look at the default options specified in
0
- # HasImage#default_options_for. The different setting options are
0
# * <tt>:resize_to</tt> - Dimensions to resize to. This should be an ImageMagick {geometry string}[http://www.imagemagick.org/script/command-line-options.php#resize]. Fixed sizes are recommended.
0
@@ -95,51 +157,6 @@ module HasImage
0
# * <tt>:invalid_image_message</tt> - The message that will be shown when the image data can't be processed.
0
# * <tt>:image_too_small_message</tt> - The message that will be shown when the image file is too small. You should ideally set this to something that tells the user what the minimum is.
0
# * <tt>:image_too_big_message</tt> - The message that will be shown when the image file is too big. You should ideally set this to something that tells the user what the maximum is.
0
- # has_image # uses all default options
0
- # has_image :resize_to "800x800", :thumbnails => {:square => "150x150"}
0
- # has_image :resize_to "100x150", :max_size => 500.kilobytes
0
- # === Some slightly more advanced examples
0
- # ==== Localizing HasImage
0
- # has_image :invalid_image_message => "No se puede procesar la imagen."
0
- # ==== Using has_image with Capistrano
0
- # When deploying using Capistrano, you will likely want to keep images
0
- # under a "system" directory so that newly deployed versions have access
0
- # has_image :resize_to => "150x150",
0
- # :base_path => File.join(Rails.root, 'public', 'system')
0
- # ==== Testing with HasImage:
0
- # If you want your tests to actually run the image processing, you should
0
- # make sure your tests write the image files somewhere outside your public
0
- # directory. Add something like this to your config/environments/test.rb:
0
- # config.after_initialize do
0
- # MyClass.has_image_options[:base_path] = File.join(RAILS_ROOT, "tmp")
0
- # If you want to stub out calls to has_image so that your tests don't do
0
- # the (slow) image processing, here's an example using Test::Unit and
0
- # Photo.any_instance.stubs(:image_data=).returns(true)
0
- # Photo.any_instance.stubs(:install_images).returns(true)
0
- # Photo.any_instance.stubs(:image_data_valid?).returns(true)
0
def has_image(options = {})
0
options.assert_valid_keys(HasImage.default_options_for(self).keys)
0
options = HasImage.default_options_for(self).merge(options)