Class: CarrierWave::ImageCardUploader
- Inherits:
-
FileCardUploader
- Object
- Uploader::Base
- FileCardUploader
- CarrierWave::ImageCardUploader
- 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
Instance Attribute Summary
Attributes inherited from FileCardUploader
Instance Method Summary collapse
-
#full_filename(for_file) ⇒ Object
add 'original' if no version is given.
-
#identifier ⇒ Object
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.
- #path(version = nil) ⇒ Object
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, #valid?
Methods included from Card::Env::Location
#card_path, #card_url, #protocol_and_host
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 |
#identifier ⇒ Object
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 |