* Add specs for ArticleImageUploader * Add specs for BadgeUploader * Add specs for CoverImageUploader * Add specs for ProfileImageUploader * Refactor uploaders to inherit from BaseUploader * Strip EXIF and GPS data from uploaded images * Add ImageMagick to the docs * Protect strip_exif
26 lines
596 B
Ruby
26 lines
596 B
Ruby
class BaseUploader < CarrierWave::Uploader::Base
|
|
include CarrierWave::BombShelter # limits size to 4096x4096
|
|
include CarrierWave::MiniMagick # adds processing operations
|
|
|
|
process :strip_exif
|
|
|
|
def store_dir
|
|
# eg. uploads/user/profile_image/1/e481b7ee.jpg
|
|
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
|
|
end
|
|
|
|
def extension_whitelist
|
|
%w[jpg jpeg jpe gif png ico bmp dng]
|
|
end
|
|
|
|
protected
|
|
|
|
# strip EXIF (and GPS) data
|
|
def strip_exif
|
|
manipulate! do |image|
|
|
image.strip
|
|
image = yield(image) if block_given?
|
|
image
|
|
end
|
|
end
|
|
end
|