Module: HasImage::ClassMethods

Defined in:
lib/has_image.rb

Instance Method Summary collapse

Instance Method Details

#has_image(options = {}) ⇒ Object

Options

  • :resize_to - Dimensions to resize to. This should be an ImageMagick geometry string. Fixed sizes are recommended.

  • :thumbnails - A hash of thumbnail names and dimensions. The dimensions should be ImageMagick geometry strings. Fixed sized are recommended.

  • :auto_generate_thumbnails - Flag to indicate whether to automatically generate thumbnails when the image_data changes (e.g. on create). If you set this to false, your application code needs to take care of generating thumbnails, e.g. using #generate_thumbnail

  • :delete - Flag to indicate if the images should be deleted from the storage (e.g. the filesystem) when the record is destroyed.

  • :min_size - Minimum file size allowed. It’s recommended that you set this size in kilobytes.

  • :max_size - Maximum file size allowed. It’s recommended that you set this size in megabytes.

  • :base_path - Where to install the images.

  • :path_prefix - Where to install the images, relative to basepath.

  • :convert_to - An ImageMagick format to convert images to.

  • :output_quality - Image output quality passed to ImageMagick.

  • :invalid_image_message - The message that will be shown when the image data can’t be processed.

  • :image_too_small_message - 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.

  • :image_too_big_message - 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.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/has_image.rb', line 170

def has_image(options = {})
  options.assert_valid_keys(HasImage.default_options_for(self).keys)
  options = HasImage.default_options_for(self).merge(options)
  class_inheritable_accessor :has_image_options
  write_inheritable_attribute(:has_image_options, options)

  after_create :install_images
  after_save :update_images
  after_destroy :remove_images

  validate_on_create :image_data_valid?

  include ModelInstanceMethods
  extend  ModelClassMethods

end