Sha256: 561dc92c4e88d7dd269a9cc3884d6ac94c4accf7ffdd0b33efe84ee259d5e273

Contents?: true

Size: 1.36 KB

Versions: 3

Compression:

Stored size: 1.36 KB

Contents

require 'mini_magick'

class ImageUploader < FileUploader
  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_fit: [200, 200]
  end
  version :large, if: :create_versions? do
    process resize_to_fit: [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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
card-1.18.6 mod/05_standard/lib/image_uploader.rb
card-1.18.5 mod/05_standard/lib/image_uploader.rb
card-1.18.4 mod/05_standard/lib/image_uploader.rb