Class: CarrierWave::ImageCardUploader

Inherits:
FileCardUploader show all
Includes:
MiniMagick
Defined in:
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 image 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

#mod

Instance Method Summary collapse

Methods inherited from FileCardUploader

#action_id, #asset_host, #bucket_config, #create_versions?, #db_content, #extension, #filename, #original_filename, #temporary_identifier, #url, #url_filename, #valid?

Methods included from FileCardUploader::Path

#cache_dir, #local_url, #local_url_base, #public_path, #retrieve_path, #store_path, #tmp_path

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 'lib/carrier_wave/image_card_uploader.rb', line 49

def full_filename for_file
  name = super(for_file)
  if name.blank? || 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 'lib/carrier_wave/image_card_uploader.rb', line 44

def identifier
  full_filename(super())
end

#path(version = nil) ⇒ Object



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

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