Sha256: 2833cb0209fce257ed61608b2c5fcbda936620d73aefd9298a3da20048b6d871

Contents?: true

Size: 1.74 KB

Versions: 62

Compression:

Stored size: 1.74 KB

Contents

require "mini_magick"

module CarrierWave
  # 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.
  class ImageCardUploader < FileCardUploader
    include CarrierWave::MiniMagick

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

    version :icon, if: :create_versions?, from_version: :small do
      process resize_and_pad: [16, 16]
    end
    version :small, if: :create_versions?, from_version: :medium do
      process resize_to_fit: [75, 75]
    end
    version :medium, if: :create_versions? do
      process resize_to_limit: [200, 200]
    end
    version :large, if: :create_versions? do
      process resize_to_limit: [500, 500]
    end

    # 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

    def identifier
      full_filename(super())
    end

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

Version data entries

62 entries across 62 versions & 2 rubygems

Version Path
card-mod-carrierwave-0.11.4 lib/carrier_wave/image_card_uploader.rb
card-mod-carrierwave-0.11.3 lib/carrier_wave/image_card_uploader.rb
card-mod-carrierwave-0.11.2 lib/carrier_wave/image_card_uploader.rb
card-mod-carrierwave-0.11.1 lib/carrier_wave/image_card_uploader.rb
card-mod-carrierwave-0.11.0 lib/carrier_wave/image_card_uploader.rb
card-1.100.0 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.99.6 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.99.5 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.99.4 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.99.3 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.99.2 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.99.1 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.99.0 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.98.3 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.98.2 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.98.1 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.98.0 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.97.0.1 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.97.0 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb
card-1.96.8 mod/carrierwave/lib/carrier_wave/image_card_uploader.rb