Skip to content

Instantly share code, notes, and snippets.

@gertig
Created July 11, 2012 21:25
Show Gist options
  • Save gertig/3093671 to your computer and use it in GitHub Desktop.
Save gertig/3093671 to your computer and use it in GitHub Desktop.
Cloudinary and CarrierWave
class AvatarUploader < CarrierWave::Uploader::Base
# include CarrierWave::RMagick
# configure do |config|
# config.remove_previously_stored_files_after_update = false
# end
include Cloudinary::CarrierWave
process :convert => 'jpg' #converts all images to pngs
process :tags => ['user_avatar'] #tags can be used to create sprites later
version :profile do
# process :resize_to_fill => [100, 100, :north]
cloudinary_transformation(width: 140, height: 140, crop: "fill", gravity: "faces", default_image: "avatar2.jpg")
end
version :nav do
cloudinary_transformation(width: 50, height: 50, crop: "fill", gravity: "faces", default_image: "avatar2.jpg")
end
version :thumbnail do
# process :resize_to_fit => [25, 25]
cloudinary_transformation(width: 25, height: 25, crop: "thumb", gravity: "faces", default_image: "avatar2.jpg")
end
# def public_id
# return model.id
# end
# Provide a default URL as a default if there hasn't been a file uploaded:
# def default_url
# "/images/noimage.png"
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
def extension_white_list
%w(jpg jpeg gif png)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment