Class: CarrierWave::ImageCardUploader

Inherits:
FileCardUploader show all
Includes:
MiniMagick
Defined in:
mod/carrierwave/lib/carrier_wave/image_card_uploader.rb

Overview

Adds image specific version handling to FileCardUploader. The ImageCardUploader creates five versions of different sizes when it uploads an imagae file: icon (16x16), small (75x75), medium (200X200), large (500x500) and the original size.

Constant Summary

Constants inherited from FileCardUploader

FileCardUploader::CONFIG_CREDENTIAL_OPTIONS, FileCardUploader::CONFIG_OPTIONS, FileCardUploader::STORAGE_TYPES

Constants included from Utilities::Uri

Utilities::Uri::SAFE_STRING, Utilities::Uri::UNSAFE

Instance Attribute Summary

Attributes inherited from FileCardUploader

#mod

Attributes inherited from Uploader::Base

#file

Attributes included from Uploader::Mountable

#model, #mounted_as

Instance Method Summary collapse

Methods included from MiniMagick

#convert, #height, #manipulate!, #resize_and_pad, #resize_to_fill, #resize_to_fit, #resize_to_limit, #width

Methods inherited from FileCardUploader

#action_id, #cache_dir, #create_versions?, #db_content, #extension, #filename, #local_url, #original_filename, #public_path, #retrieve_path, #store_path, #tmp_path, #url, #url_filename

Methods included from Card::Env::Location

#card_path, #card_url, #page_path

Methods included from Uploader::Serialization

#as_json, #serializable_hash, #to_json, #to_xml

Methods included from Uploader::DefaultUrl

#default_url, #url

Methods included from Uploader::Versions

#recreate_versions!, #url, #version_exists?, #version_name, #versions

Methods included from Uploader::Callbacks

#with_callbacks

Methods included from Uploader::Processing

#process!

Methods included from Uploader::FileSize

#size_range

Methods included from Uploader::ContentTypeBlacklist

#content_type_blacklist

Methods included from Uploader::ContentTypeWhitelist

#content_type_whitelist

Methods included from Uploader::ExtensionBlacklist

#extension_blacklist

Methods included from Uploader::ExtensionWhitelist

#extension_whitelist

Methods included from Uploader::Remove

#remove!

Methods included from Uploader::Download

#download!, #process_uri

Methods included from Uploader::Cache

#cache!, #cache_name, #cache_path, #cache_stored_file!, #cached?, #retrieve_from_cache!, #sanitized_file

Methods included from Uploader::Store

#filename, #retrieve_from_store!, #store!, #store_path

Methods included from Uploader::Mountable

#initialize

Methods included from Uploader::Url

#to_s, #url

Methods included from Uploader::Proxy

#blank?, #content_type, #current_path, #length, #read, #size

Instance Method Details

#full_filename(for_file) ⇒ Object

add 'original' if no version is given



49
50
51
52
53
54
55
56
57
# File 'mod/carrierwave/lib/carrier_wave/image_card_uploader.rb', line 49

def full_filename for_file
  name = super(for_file)
  if version_name
    name
  else
    parts = name.split "."
    "#{parts.shift}-original.#{parts.join('.')}"
  end
end

#identifierObject

version :small_square, if: :create_versions?, from_version: :medium_square do process resize_to_fill: [75, 75] end version :medium_square, if: :create_versions? do process resize_to_fill: [200, 200] end

In case we decide to support the squared versions we have to update all existing images with the following snippet: Card.search(type_id: Card::ImageID) do |card| card.image.cache_stored_file! card.image.recreate_versions! end



44
45
46
# File 'mod/carrierwave/lib/carrier_wave/image_card_uploader.rb', line 44

def identifier
  full_filename(super())
end

#path(version = nil) ⇒ Object



12
13
14
# File 'mod/carrierwave/lib/carrier_wave/image_card_uploader.rb', line 12

def path version=nil
  (version && version != :original) ? versions[version].path : super()
end